Subj : Re: Lifespan of Function objects To : Stephen Jones From : Brendan Eich Date : Tue Aug 05 2003 03:28 pm Stephen Jones wrote: >Let's say that I create a JSContext using JS_NewContext and then load a >script into that context > "on that context" -- contexts are for executing scripts on, properties are defined *in* objects. Don't mix context up with object (scope). A context does define some GC roots, such as its globalObject member (got and set via the JS_{Get,Set}GlobalObject API), of course. But the context is not an object itself; you have to create a global object and associate it with the context (either via JS_SetGlobalObject or JS_InitStandardClasses). > using JS_EvaluateScript. In that script I set a >property on a global object to point to a function that was defined in that >script . . . > >function Test( ) >{ > // body >} > >object.onError = Test; > >What happens if I destroy the script context and then try to access that >function? Is it protected from GC because it's a property of a global >object? Does it need to be rooted? Will it always be destroyed when the >context is destroyed? > > Maybe -- what other references to that object might still be found from a GC root? If you can't find any, then it will be GC'd. You have to arrange for at least one such strong reference to exist, if you want to destroy the context but keep the objects (|object| above, and the global object, and of course the Test function object) around afterward. /be .