Search code examples
javascriptcspidermonkey

Spidermonkey: How do I delete the global object


I can create a global objects with

JS_NewCompartmentAndGlobalObject

(SM 1.8.5) or a similar function

but how do I delete the global object. As far as I know the global object is rooted and thus no GC thing. At the end I can call JS_DestroyContext but to call JS_GC I must have a context. When is the global object garbage collected?


Solution

  • The JS_DestroyContext call does garbage collection to reclaim memory used by the context's global. Presumably you should set your JS::Rooted to JSVAL_NULL before destroying the context so there are no stack roots of the global when the GC runs.