0

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?

2 Answers2

1

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.

jwilm
  • 455
  • 4
  • 11
0

Read this topic topic. You need to create you object using var if you want to remove it in future. Or if you don't want to use it just put to it null. if this object was created without var it will not be processed by your GC until you don't close the window.

Community
  • 1
  • 1
Simcha
  • 3,300
  • 7
  • 29
  • 42