Subj : Re: Garbage collection To : netscape.public.mozilla.jseng From : Jochen Stier Date : Fri Sep 03 2004 11:29 am Well, I am answering my own question again, but maybe it is good feedback for everyone. I used for (int j=0; j<10; j++) { char lBuffer[100]; itoa(j, lBuffer, 10); strcat(lBuffer, "testClass"); JS_DefineObject(sJSContext, sJSProto, lBuffer, &testClass, 0, JSPROP_PERMANENT); } instead of the loop below and it works... "Jochen Stier" wrote in message news:cha8uh$gbm1@ripley.netscape.com... > Hi, I am doing the following.... > > sJSRuntime = JS_NewRuntime(0x100000); > sJSContext = JS_NewContext(sJSRuntime, 0x1000); > sJSProto = JS_NewObject(sJSContext, &sJSClass, NULL, NULL); > > JS_AddRoot(sJSContext, &sJSProto); > > for (int j=0; j<10; j++) > { > JS_NewObject(sJSContext, &testClass, 0, sJSProto); > } > > JS_GC(); > > What happens is that 10 object are being gc-ed, allthough they are a "child" > of sJSProto. Am I missing something > here ? How can I protect the 10 objects from being gc-ed themselves. I > cannot use JS_AddRoot within the loop > because &lObject is always the same .... > > for (int j=0; j<10; j++) > { > JSObject* lObject = JS_NewObject(sJSContext, &testClass, 0, > sJSProto); > JS_AddRoot(sJSContext, &lObject ); > } > > Basically I am trying to build a cache of objects during startup and new > delete them till shutdown. > > > Cheers > Jochen > > > .