JS_GC

  • Revision slug: SpiderMonkey/JSAPI_Reference/JS_GC
  • Revision title: JS_GC
  • Revision id: 147052
  • Created:
  • Creator: Dria
  • Is current revision? No
  • Comment

Revision Content

{{template.Jsapiref()}}

Summary

Function

Performs garbage collection in the JS memory pool.

Syntax

void JS_GC(JSContext *cx);
Name Type Description
cx JSContext * Pointer to a JS context from which to derive runtime information.

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 you use JS_malloc and JS_realloc to allocate memory for executable script contexts, these routines automatically invoke the garbage collection routine.

When your scripts create many objects, you may want to call JS_GC directly in your code, particularly when request ends or a script terminates. To run garbage collection only when a certain amount of memory has been allocated, you can call JS_MaybeGC instead of JS_GC.

See Also

Groups Functions
Documents {{template.LXRSearch("ident", "i", "JS_GC", "LXR ID Search")}}
Entries

JS_MaybeGC, JS_malloc, JS_realloc

Revision Source

<p> 
{{template.Jsapiref()}}
</p>
<h2 name="Summary"> Summary </h2>
<p><b>Function</b>
</p><p>Performs garbage collection in the JS memory pool.
</p>
<h2 name="Syntax"> Syntax </h2>
<pre>void JS_GC(JSContext *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>JSContext *</code></td>
<td>Pointer to a JS context from which to derive runtime information.</td>
</tr>
</tbody></table>
<h2 name="Description"> Description </h2>
<p><code>JS_GC</code> performs garbage collection, if necessary, of JS objects, doubles, and strings that are no longer needed by a script executing in a specified <code>JSContext</code>, <code>cx</code>. Garbage collection frees space in the memory pool so that it can be reused by the JS engine.
</p><p>When you use <code><a href="en/JSAPI_Reference/JS_malloc">JS_malloc</a></code> and <code><a href="en/JSAPI_Reference/JS_realloc">JS_realloc</a></code> to allocate memory for executable script contexts, these routines automatically invoke the garbage collection routine.
</p><p>When your scripts create many objects, you may want to call <code>JS_GC</code> directly in your code, particularly when request ends or a script terminates. To run garbage collection only when a certain amount of memory has been allocated, you can call <code><a href="en/JSAPI_Reference/JS_MaybeGC">JS_MaybeGC</a></code> instead of <code>JS_GC</code>.
</p>
<h2 name="See_Also"> See Also </h2>
<table class="fullwidth-table">
<tbody><tr>
<td>Groups</td>
<td><a href="en/JSAPI_Reference#Functions">Functions</a></td>
</tr>
<tr>
<td>Documents</td>
<td>{{template.LXRSearch("ident", "i", "JS_GC", "LXR ID Search")}}</td>
</tr>
<tr>
<td>Entries</td>
<td>
<p><a href="en/JSAPI_Reference/JS_MaybeGC">JS_MaybeGC</a>,
<a href="en/JSAPI_Reference/JS_malloc">JS_malloc</a>,
<a href="en/JSAPI_Reference/JS_realloc">JS_realloc</a>
</p>
</td>
</tr>
</tbody></table>
Revert to this revision