Subj : Re: Garbage Collection Woes To : netscape.public.mozilla.jseng From : "Stephen Jones" Date : Mon Apr 28 2003 10:35 am One more piece of information . . . this only seems to happen to objects created in contexts other than the global context . . . am I doing something wrong when executing GC? This is the code I am using . . . while( ( theCurrentContext = JS_ContextIterator( m_JSRunTimePtr, &theContextIterator ) ) != NULL ) { JS_GC( theCurrentContext ); } Is the "live-thing" graph different for different contexts? 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 > > .