Subj : Re: GC question To : netscape.public.mozilla.jseng From : lyg Date : Fri May 28 2004 11:11 am "MA" wrote in message news:69bf8050.0405270519.af6863@posting.google.com... > > > > Why? is the JS_MaybeGC never be called? Why the created AppObj and its > > properties is not freed when I JS_RemoveRoot()? > > what is wrong ? > > > > All the objects you create are global objects. According to my understanding, > global objects are never GC'ed. So, you need to manually free them, not > rely on GC to do that. > > because when i open a new document, i need a "root object" to manager the objects created in the new document, I have to create many global objects for the root objects. when I access the opened document, i just fetch the rooted "root object" and JS_SetGlobalObject(). In other words, at the same time, there is only one object as the global object and the others are rooted not to GCed. When i want close the document, I will JS_RemoveRoot(rootedObj) to let it GCed. Now it is not the global object, why not be GCed? > Secondly, you are passing a pointer to an object when calling > JS_AddRoot. This is wrong. Pass a "pointer to object-pointer" when > calling JS_AddRoot. This, of course, has nothing to do with your > problem. > > I think it is right to use JS_AddRoot(cx, &obj); not like JS_AddRoot(cx, obj); the follow is cited from jsapi.h /**/ A JS GC root is a pointer to a JSObject *, JSString *, or jsdouble * that * itself points into the GC heap (more recently, we support this extension: * a root may be a pointer to a jsval v for which JSVAL_IS_GCTHING(v) is true). * * Therefore, you never pass JSObject *obj to JS_AddRoot(cx, obj). You always * call JS_AddRoot(cx, &obj), passing obj by reference. And later, before obj * or the structure it is embedded within goes out of scope or is freed, you * must call JS_RemoveRoot(cx, &obj). > MA .