Join MDN and developers like you at Mozilla's View Source conference, November 2-4 in Portland, Oregon. Learn more at

JS LockGCThing

This template is obsolete. Do not use it.

This feature has been removed from the Web. Though some browsers may still support it, it is in the process of being dropped. Do not use it in old or new projects. Pages or Web apps using it may break at any time.

Protect a specified JS item from garbage collection.


JSBool JS_LockGCThing(JSContext *cx, void *thing);

JSBool JS_UnlockGCThing(JSContext *cx, void *thing);
Name Type Description
cx JSContext * A context. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext.
thing void * Pointer to the item to protect.


JS_LockGCThing is a deprecated function that protects a specified item, thing, associated with an executable script context, cx, from garbage collection. thing is a pointer to a jsdouble, JSString, or JSObject.

JS_UnlockGCThing removes a lock from a specified item, thing, allowing it to be garbage collected when the JavaScript engine determines it is unreachable.

JS_LockGCThing and JS_UnlockGCThing are available only for backward compatibility with existing applications. Use JS_AddRoot and JS_RemoveRoot instead.

MXR ID Search for JS_LockGCThing
MXR ID Search for JS_UnlockGCThing

Document Tags and Contributors

Last updated by: Jorend,