Register a custom string memory manager.
intN JS_AddExternalStringFinalizer(JSStringFinalizeOp finalizer);
||Pointer to a callback function, described below. The JS engine will automatically call this function each time a string created by JS_NewExternalString is garbage-collected.|
typedef void (*JSStringFinalizeOp)(JSContext *cx, JSString *str);
||Pointer to a JSContext which the finalizer may use for certain very limited operations (not documented). Since the JSStringFinalizeOp callback is called during garbage collection, it must avoid most JSAPI functions. (Is cx guaranteed to be non-NULL?)|
The string being finalized. This is always a string that the application previously created by calling
The callback may not keep a reference to this
Add a finalizer for external strings created by JS_NewExternalString using a type-code returned from this function, and that understands how to free or release the memory pointed at by
Returns a nonnegative type index if there is room for finalizer in the global GC finalizers table, else returns -1. If the engine is compiled JS_THREADSAFE and used in a multi-threaded environment, this function must be invoked on the primordial thread only, at startup--or else the entire program must single-thread itself while loading a module that calls this function.