Subj : Re: Newbie question. GC or memory managment. To : netscape.public.mozilla.jseng From : J.P. Date : Fri Aug 27 2004 03:15 pm Thanks for the responses. Espicially Brendan. You have been very patient. During the past a few day's reading, i have seen several notes talking about "racing with GC". My understanding is: Given following code: JS_BeginRequest(ctx); DoSomething(); JS_EndRequest(ctx); If DoSomething() takes too long, the GC will never get a chance to run, right? In my code: ctx = JS_NewContext(); JS_BeginRequest(ctx); DoSomething(); JS_EndRequest(ctx); ctx = JS_DestroyContext(ctx); I sololy depend on the JS_GC() invoked by JS_DestroyContext(). Is it safe to assume that all memory associated with that ctx will be released properly? Actually, since the ctx was used only by one thread, i was wondering if JS_BeginRequest() and JS_EndRequest() are necessary. Brendan Eich wrote: > J.P. wrote: > >> In my code, I have multiple threads sharing the same runtime. Each >> thread has his own contexts. >> >> Do I need to compile the JS engine with JS_THREADSAFE defined? > > > > Yes. > > >> Do I need to use JS_BeginRequest and JS_EndRequest to bracket the JS >> API calls in each thread? > > > > Yes. Bracket batches of calls made from your own non-blocking code. Of > course you don't need to begin and end requests within your own native > functions, getters, setters, etc. that the engine calls (JSClass hooks, > JSNative functions). > > /be .