Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 147054 of JS_GC

  • Revision slug: SpiderMonkey/JSAPI_Reference/JS_GC
  • Revision title: JS_GC
  • Revision id: 147054
  • Created:
  • Creator: Jorend
  • Is current revision? No
  • Comment link [[JS_SetGCCallback]] and a bunch of other little edits

Revision Content

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

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.

{{ LXRSearch("ident", "i", "JS_GC") }}

Revision Source

<p>{{ Jsapi_ref_header("JS_GC") }}
</p><p>Performs garbage collection in the JS memory pool.
</p>
<h2 name="Syntax"> Syntax </h2>
<pre class="eval">void <b>JS_GC</b>(<a href="en/JSContext">JSContext</a> *cx);
</pre>
<table class="fullwidth-table">
<tbody><tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
<tr>
<td><code>cx</code></td>
<td><code><a href="en/JSContext">JSContext</a> *</code></td>
<td>The context to use. <code>JS_GC</code> collects unreachable objects from the associated <code><a href="en/JSRuntime">JSRuntime</a></code>, regardless of which <code>JSContext</code> created them. This context is passed to all <code><a href="en/JSGCCallback">JSGCCallback</a></code>, <code><a href="en/JSClass.mark">JSClass.mark</a></code>, and <code><a href="en/JSClass.finalize">JSClass.finalize</a></code> hooks triggered during garbage collection.</td>
</tr>
</tbody></table>
<h2 name="Description"> Description </h2>
<p><code>JS_GC</code> performs garbage collection, if necessary, of JS objects, numbers, and strings that are no longer reachable in the runtime of <code>cx</code>. Garbage collection frees memory so that it can be reused by the JS engine.
</p><p>When your scripts create many objects, you may want to call <code>JS_GC</code> directly in your code, particularly when a script terminates or when the application has idle time. To perform garbage collection only if needed, call <code><a href="en/JS_MaybeGC">JS_MaybeGC</a></code> instead.
</p><p>Use <code><a href="en/JS_SetGCCallback">JS_SetGCCallback</a></code> to add hooks that are called during garbage collection.
</p><p>{{ LXRSearch("ident", "i", "JS_GC") }}
</p>
Revert to this revision