Subj : Memory growth problem To : netscape.public.mozilla.jseng From : "Mike McIntosh" Date : Thu May 15 2003 09:27 pm Hi, I'm having a problem with memory steadily growing as my app runs. I have a precompiled pool of contexts each of which has it's own global object. This global object is used to create custom objects and also to extend the available global functions as follows :- void initGlobal(JSContext* cx, JSObject* glob) { if (glob) { JSBool builtins = JS_InitStandardClasses(cx, glob); if (builtins) { JS_DefineProperties(cx, glob, global_props); JS_DefineFunctions(cx, glob, global_functions); } } My original code looked like :- CSafeRequest request(m_cx); jsb = JS_ExecuteScript(m_cx, scope, cjs->get_Handle(), rval); but I noticed that not all finalizers were being called on objects created by the script. After reading some previous posts, I tried modifying this to use a scope object as follows :- CSafeRequest request(m_cx); JSObject* scope = JS_NewObject(m_cx, &global_class, m_glob, NULL); if (scope) { JS_SetGlobalObject(m_cx, scope); jsb = JS_ExecuteScript(m_cx, scope, cjs->get_Handle(), rval); JS_ClearScope(m_cx, scope); } [The CSafeRequest just wraps up JS_SetContextThread/ JS_BeginRequest/JS_EndRequest calls.] With the 'scoped' version I can see my finalizers being called for the custom objects in the script. But there is still a steady build up of memory which seems to be being allocated via jsapi.c (line 1432):: JS_malloc. I also periodically call JS_GC. What is the best architecture to allow memory allocated during a script execution to be released?. How do I track these allocations down?. I'm on Win32 with latest beta trunk. I have JS_THREADSAFE, GC_MARK_DEBUG defined. Mike .