Visit Mozilla.org

JS GC

From MDC

Performs garbage collection in the JS memory pool.

[edit] 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 all JSGCCallback, JSClass.mark, and JSClass.finalize hooks triggered during garbage collection.

[edit] Description

JS_GC performs garbage collection, if necessary, of JS objects, numbers, and strings that are no longer reachable in the runtime of cx. Garbage collection frees memory 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.

Use JS_SetGCCallback to add hooks that are called during garbage collection.

LXR ID Search for JS_GC