{{template.Jsapi_ref_header("JS_GC")}}
Performs garbage collection in the JS memory pool.
Syntax
void JS_GC(JSContext *cx);
Name | Type | Description |
---|---|---|
cx |
JSContext * |
The context to use. JS_GC collects unreachable objects from the associated JSRuntime , regardless of which JSContext created them. This context is passed to JSClass.finalize hooks. |
Description
JS_GC
performs garbage collection, if necessary, of JS objects, doubles, and strings that are no longer needed by a script executing in a specified JSContext
, cx
. Garbage collection frees space in the memory pool so that it can be reused by the JS engine.
When your scripts create many objects, you may want to call JS_GC
directly in your code, particularly when a script terminates or when the application has idle time. To perform garbage collection only if needed, call JS_MaybeGC
instead of JS_GC
.
{{template.LXRSearch("ident", "i", "JS_GC")}}