Subj : GC question To : netscape.public.mozilla.jseng From : lyg Date : Wed May 26 2004 04:11 pm I have a puzzling question in my application. My application works like that: it do not support multithread. so I only create one JSContext. rt = JS_NewRuntime(JSRUNTIME_SIZE); if(!rt) return JS_FALSE; cx = JS_NewContext(rt, CONTEXT_SIZE); I defined a array to contain the created AppObjs. JSObject *AppObjPtr[APP_MAX_NUM]; static int appIndex = 0; when I open a new document. I create a object for global object and rooted it not to be gc. { if (!(AppObj = JS_NewObject (cx, &AppObj_class, NULL, NULL))) return JS_FALSE; AppObjPtr[appIndex] = AppObj; JS_AddRoot(cx, (void*)(AppObjPtr + appIndex)); appIndex++; JS_InitStandardClasses (cx, AppObj); cx->globalObject = AppObj; // do something else } when the number of created AppObj is big than APP_MAX_NUM; I begin remove all the rooted AppObj and call JS_MaybeGC() to collect the unavailable gcthings. { for( k = 0; k < APP_MAX_NUM; k++ ) { JS_RemoveRoot( cx, (void*)(AppObjPtr + k) ); AppObjectPtr[k] = 0; } JS_MaybeGC(); } I assigned the JSRUNTIME_SIZE a bigger value about 400k, and i suppose open APP_MAX_NUM documents need about 200k. but when i let my application run automaticly, it always met the condition which rt->gcBytes > rt->gcMaxBytes, and obj = NULL; /* Allocate an object from the GC heap and zero it. */ obj = (JSObject *) js_AllocGCThing(cx, GCX_OBJECT); if (!obj) return NULL; Why? is the JS_MaybeGC never be called? Why the created AppObj and its properties is not freed when I JS_RemoveRoot()? what is wrong ? thanks very much for any help. and hope somebody can point some error or unlogical place in my app. .