Subj : Re: questions of js_GC To : lyg From : Brendan Eich Date : Wed Mar 24 2004 11:43 am lyg wrote: > Hi, > In my app, I implemented a Global object named GlobObj. > and use > JS_AddRoot(cx, &cx->globalObject); For the last time, stop including header files other than jsapi.h. You should *not* be including jscntxt.h. Worse, there is no need to add a root for cx->globalObject -- it's already a root-by-definition that the GC scans! > > In the following, > I use JS_NewObject(....) to create a fieldObj, and then > > JS_SetProperty(cx,GlobObj, "field", &(jsval)fieldObj). Stop casting till your code compiles. Use the right typed variable, and use the JSVAL macros. (Apparently you are using C++.) > optionsObj = JS_NewArrayObject(.......) > JS_SetProperty(cx, FieldObj, "options", &(jsval)optionsObj) > > In this case, can I protect the optionsObj not to be collected by js_gc() in > using js_addroot() function? There is no need to do that if FieldObj is well-connected to the live object graph. You don't root every object, you root only those that are not named by properties in other well-connected objects. > In my app, why the optionsObj->map->slots[0] and slots[1] ... are changed to > 0xcdcdcdcd or 0x10101010 after js_gc()? Because you have rooting bugs. /be .