Subj : Re: Memory growth problem To : Mike McIntosh From : Brendan Eich Date : Sat May 17 2003 01:27 pm >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. > Need the stack backtrace(s) for that JS_malloc, as I posted recently. I did want to get back to you on the scope object usage above. It seems fine, although there is a potential for unwanted sharing and security domain violation in the shared m_glob prototype. An option that avoids those hazards is to use JS_ResolveStandardClass from your global_class.resolve hook, and JS_EnumerateStandardClasses from ..enumerate -- then you don't need the m_glob prototype with its standard classes, and each scope object gets only those standard objects that it actually uses. If you prefer to stick with the shared prototype, you'll want to use the JS_SealObject(cx, m_glob, JS_TRUE) on m_glob after you've called JS_InitStandardClasses on it, but before it is otherwise used. /be .