Subj : Re: custom object lifetime question. To : donteventthinkaboutit From : Brendan Eich Date : Tue Jul 20 2004 09:11 am donteventthinkaboutit@sbcglobal.net wrote: > Two questions really. > > One: > I am using JS_DefineObject to create objects of a custom class in my > application. Since this isn't a JS_New* function, As far as I can > gather, I do not need to use JS_AddRoot. Is this correct? So long as the object in which you define the property strongly referencing the new object created by JS_DefineObject is itself strongly connected to the live object graph (either named by another property in yet another well-connected live object, or else the object in which you defined the new object is rooted explicitly or implicitly). You can see how liveness depends on being connected to a graph that starts from GC roots, both those you define via JS_AddNamedRoot, and those implicit in the engine's API (JS_SetGlobalObject and JS_InitClass, e.g.). > Two: > When my application is done with this object, How do I tell > spidermonkey that I no longer need it? It is possible that some > variables in the runtime may maintain references to this object, even > after the Native application is done with it, so it cannot be > destroyed outright. How do I signal to signal to spidermonkey that > the object can now be garbage collected as far as the Native app > is concerned? If you use JS_DefineObject, you are (a) creating a new object; (b) binding it to another object by defining a property in that other object whose value is a reference to the new object created in (a). If you no longer need the object created in (a), you need *at the least* to make the object in which you defined it as a property value become garbage, or else delete the property defined in (b). /be .