<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.5.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "JavaScriptCore",
  "identifier" : "/documentation/JavaScriptCore/JSGarbageCollect(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "JavaScriptCore"
    ],
    "preciseIdentifier" : "c:@F@JSGarbageCollect"
  },
  "title" : "JSGarbageCollect(_:)"
}
-->

# JSGarbageCollect(_:)

Performs a JavaScript garbage collection.

```
func JSGarbageCollect(_ ctx: JSContextRef!)
```

## Parameters

`ctx`

The execution context to use.

## Discussion

The system doesn’t collect JavaScript values that are on the machine stack, are in a register, are receiving protection from [`JSValueProtect(_:_:)`](/documentation/JavaScriptCore/JSValueProtect(_:_:)), are the global object of an execution context, or are reachable from any such value.

During JavaScript execution, you don’t have to call this function because the JavaScript engine collects garbage as necessary. The system automatically destroys JavaScript values within a context group when the last reference to the context group releases.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)