Subj : Re: JS_GetArrayLength() crashing (garbage collection issue) To : netscape.public.mozilla.jseng From : smaraux Date : Fri Feb 25 2005 02:23 am Brendan Eich wrote in message news:<421E72C5.6070509@meer.net>... > sebastien maraux wrote: > > > JS_AddRoot(pJSContext, pDataHolder->pChildrenArray); > > You need to pass &pDataHolder->pChildrenArray -- see the API docs and > many other postings (google groups is useful to find these) on this. > > You should also compile with DEBUG defined, in which case you should be > seeint JS_ASSERTs about roots pointing outside the GC heap, etc. > > /be OK, thanks. I now get another issue : I am adding each children of my pDataHolder->pChildrenArray to root. A children is typically added with JSObject *localObj = JSConstructObject(...my objectClass...); JS_AddRoot(context, &localObj); jsval localVal = OBJECT_TO_JSVAL(localObj); JS_SetElement(Context, pDataHolder, (jsint) u4Index, &localVal ); But (I guess that) as it is local, localObj is being deleted, causing a bit later a JS_GC call to crash. I would like to add real content of the array (element) to root instead of localObj (and I would like to be able to do so for double, string and other gcthing too). Is there a mean to do that ? On the other case, I will have to keep two references to my object and maintain two different arrays (one from array, another from a basic array of void pointers for ex. for being able to keep pointer alive), which is a great lost of space. Last solution would be not to use JSArrays to do that, but a hand made array instead allowing to do what I want (retrieving adress of each element) ? Thank you for your answer .