Subj : Re: Custom C++ objects with references and garbage collecting in To : Brendan Eich From : Mads Bondo Dydensborg Date : Tue Mar 29 2005 07:02 am Brendan Eich skrev: First, thanks for you reply, and sorry for the delay - have been away on easter holiday. > Mads Bondo Dydensborg wrote: > >> >> I want to say to the GC: "Do not clean B before a and another a have >> been cleaned" > > > > Then you need a and anothera to refer to b (I think you mean b, not B, > here), Yes, sorry about that, wrote B a couple of times where I meant B. > each using a strong reference. A strong reference could be a > property in each a, anothera, etc. -- call it parent -- such that > a.parent == b. You can set such a property with JS_SetProperty, or if > you want it to be readonly and permanent, JS_DefineProperty. OK, that sounds pretty easy > If you don't want a property, you could have a rooted pointer in the > private data of each a, say a.[[parent]] (I'm making up notation to > distinguish the internal property [[parent]] from the property parent > proposed in the last paragraph). You could root this pointer using > JS_AddNamedRoot, remembering to remove it with JS_RemoveRoot when a is > being finalized. Or, and this is better, you could have the JSClass > corresponding to the C++ class A define a mark hook. Excuse my lack of knowledge - these mark hooks are new to me. Are they documented anywhere, besides the comments in some of the header files? >> From reading the docs, it seems to me, that one perhaps should make a >> and another a properties of b? > > > > No, that would keep each a alive so long as b is not garbage, but you > want the other way round (or perhaps you want both). Hmm. That is kind of confusing. You are saying, that if object has property object.name, object.name will be kept alive as long as object is not garbage, but object can be cleaned before object.name? Hmm. I suppose it does make sense, although it is a bit confusing at first. > > >> Any help will be greatly appriciated. A pointer to some docs about how >> to use the SpiderMonkey GC "right" would be also be appreciated. > > > > I assume you've read all the docs available at > http://www.mozilla.org/js/spidermonkey/ Yes. >-- you ought to read up on > garbage collection too. I was under the impression that it was a pretty simple (although not necc. simple to implement) concept. Can you recommend any texts that would better enable me to understand the details of spidermonkey gc? Thanks, Mads .