The JSClass.finalize callback is a hook for destructor code. The garbage collector calls the finalize hook of each JSObject it collects.
typedef void (*JSFinalizeOp)(JSContext *cx, JSObject *obj);
| Name | Type | Description |
|---|---|---|
cx |
JSContext * |
The JS context in which garbage collection is taking place. |
obj |
JSObject * |
The object being destroyed. |
The JSClass.finalize callback 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.

For other ways to interact with garbage collection (e.g. implementing weak references), see JS_SetGCCallback.
Page last modified 15:53, 5 Feb 2008 by Jorend