Subj : Re: Garbage Collection Woes To : netscape.public.mozilla.jseng From : "Stephen Jones" Date : Fri Apr 25 2003 03:36 pm To be more specific: I have one object that is JS_DefineProperty'd on the global object another object JS_DefineProperty'd on that and another object JS_DefineProperty'd on that . . . then an object that I JS_SetProperty or JS_DefineObject on that one keeps getting GC'd example: root.object1.object2.gcobject . . . shouldn't that be considered "live" Thanks, - S "Stephen Jones" wrote in message news:b8bugv$aen1@ripley.netscape.com... > I thought I had Garbage Collection in SpiderMonkey figured out, but it turns > out I was wrong and I can't figure it out to save my life. I've read all the > old posts to this newsgroup regarding Garbage Collection, all the GC tips on > the web I can find and it seems to make sense, but it doesn't work and I > can't figure out what I'm doing wrong. > > I was just using JS_AddNamedRoot for everything, but it turns out that > doesn't work for (probably) obvious reasons. If you have multiple objects > that are using the same object and one goes out of scope and removes the > root, then that object is unprotected. > > From what I understand, basically, you are supposed to protect object froms > GC by setting them as properties on other protected objects. Please correct > me if I'm wrong. > > So, I have a root object that I "attach" to the global object using > JS_DefineProperty (I assume that this protects this object, I can't tell > because I have AddRoots everywhere . . . I'm trying to understand this so I > can clean it up). This root object has various properties (defined using > tiny ids on the prototype of the root object) that are JSObjects as well. > After an object is instantiated from the prototype (JS_NewObject), to > protect these objects from GC, I call JS_SetProperty passing in the > JSObject. This does not work, especially for read-only properties. If I run > GC at this point, these objects are destroyed. Note: if I first retrieve the > property, then run GC, it is not garbage collected (maybe this is because it > is stored in a local root for the return value of the getter?) > > Anyway, can someone please set me straight? How should this work? What am I > missing? > > Thanks, > - S > > .