Subj : JS_AddRoot & finalize problem To : netscape.public.mozilla.jseng From : anton muhin Date : Thu Jul 22 2004 09:10 pm Hello, dear gurus! I have the following problem that I still cannot solve after googling & documentation reading. I want to store in private data a reference (intenationally vagous term) to JS Array. Here the way I go: In construct object: JSObject * const a = JS_NewArrayObject(cx, nElements, elements); JSObject * * root = new (JSObject*)(a); JS_AddRoot(cx, root); if (!JS_SetPrivate(cx, obj, root)) { JS_RemoveRoot(cx, root); return JS_FALSE; } return JS_TRUE; In finalizer: JSObject * * root = (JSOBject**)JS_GetPrivate(cx, obj); JS_RemoveRoot(cx, root); delete root; However, in this case finalizer isn't get called!!! And, obviously, I get warnings: JS engine warning: leaking GC root '' at ... JS engine warning: 1 GC root remains after destroying the JSRuntime. This root may point to freed memory. Objects reachable through it have not been finalized. If I comment out JS_AddRoot in construct phase, finalizer gets called. Can somebody explain what goes on and what is the right they to achieve my goal? I especially don't understand why my object doesn't get garbage collected---it seems that I doesn't introduce any refernces to it. Session is quite simple: I just launch the jsshell and leave it. The object gets constructed as a prototype of the class I add into the object model. Thank you in advance! anton. .