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.

JSFinalizeOp

This article needs a technical review. How you can help.

JSFinalizeOp is the type of JSClass.finalize.

Syntax

typedef void
(* JSFinalizeOp)(JSFreeOp *fop, JSObject *obj);
Name Type Description
cx JSContext * The JS context in which garbage collection is taking place.
obj JSObject * The object being destroyed.

Description

The JSFinalizeOp is analogous to Java finalizers or C++ destructors. The garbage collector calls this callback for each object it collects. The finalizer's job is to clean up any resources allocated by the instance which wouldn't normally be cleaned up by the garbage collector (private data stored in the object by the application, file handles, etc.)

Finalizers must never store a reference to obj.

Warning: This hook is called during garbage collection. Any JSAPI call that would allocate memory from the GC heap will fail if called from a finalizer.

For other ways to interact with garbage collection (e.g. implementing weak references), see JS_SetGCCallback.

JSClass hooks

JSClass offers the following hook:

  • The JSClass.finalize callback is a hook for destructor code. The garbage collector calls the finalize hook of each JSObject it collects.

See Also

Document Tags and Contributors

 Contributors to this page: kscarfone, arai
 Last updated by: kscarfone,