{{SpiderMonkeySidebar("JSAPI")}}
Performs garbage collection in the JS memory pool.
Syntax
void JS_GC(JSContext *cx); // Added in SpiderMonkey 52 void JS_GC(JSRuntime *rt); // Obsolete since JSAPI 50 void JS_GC(JSContext *cx); // Obsolete since JSAPI 14
Name | Type | Description |
---|---|---|
cx |
{{jsapixref("JSContext", "JSContext *")}} | The context to for which to perform garbage collection. {{ Jsapi_minversion_inline("52") }} |
rt |
{{jsapixref("JSRuntime", "JSRuntime *")}} | The runtime to for which to perform garbage collection. {{ obsolete_inline("jsapi50") }} |
Description
JS_GC
performs garbage collection of JS objects, strings and other internal data structures that are no longer reachable in the specified context or runtime. Garbage collection frees memory so that it can be reused by the system.
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 {{jsapixref("JS_MaybeGC")}} instead.
Use {{jsapixref("JS_SetGCCallback")}} to add hooks that are called during garbage collection.
See Also
- {{ LXRSearch("ident", "i", "JS_GC") }}
- {{jsapixref("JS_MaybeGC")}}
- {{bug(737364)}} -- Changed to
JSRuntime
- {{bug(1283855 )}} -- Changed to
JSContext