Subj : Re: differnce btwn JS_AddRoot and JS_LockGCThing??? To : netscape.public.mozilla.jseng From : Aaron Reed Date : Thu May 27 2004 04:38 pm Aaron Reed wrote: > Hey, > > Ok, we compile a function using scriptContext->CompileFunction and then > we want to prevent the returned funcObj from being garbage collected. If > we us JS_LockGCThing, it is protected just fine. If we use JS_AddRoot > (since JS_LockGCThing is deprecated), this throws an assertion in > gc_root_marker. gc_root_marker is checking to see if the item was > allocated from the gcArenaPool. However what it is checking isn't the > object that we rooted, but rather the return value from > JSVAL_TO_GCTHING(v). And it isn't marking the obj that we rooted > either, it is marking the return value from JSVAL_TO_GCTHING(v). > > So why the difference? Why doesn't gc_lock_marker care about the JSVAL? > Should we just go ahead and use JS_LockGCThing? If we should use > JS_AddRoot, how do we ensure that we are marking the right thing? > > Thanks for your help, > --Aaron If you are interested, looks like JS_AddRoot takes a pointer to the value that you really want to keep around. JS_LockGCThing takes the value that you want to keep around. Make sure if you use JS_AddRoot that you keep the pointer around (alloc it, don't use local stack value) or you'll probably take an exception in gc_root_marker later on when that memory is reused. That is where I was screwing up. .