On May 18, 2011, at 7:34 PM, Murray S. Kucherawy wrote:
I’m working on an application that’s multi-threaded, and to avoid a newstate-load-pcall-close series for every time I want to invoke a script, I’m thinking of allocating a pool of states and just pulling one out when it’s time to run, which leaves me with just load-pcall every time.
One thing I’m not certain about with that design: Will the garbage collector purge any global variables that exist in the state on completion of the pcall, or will they linger around for the next load-pcall on the same state object? If the latter, can I use some getfenv/setfenv magic to reset things for the next iteration? Or do I have to bite the bullet and do it the more expensive way?
Global variables, by their nature, prevent garbage collection. You'll have to nil them out before they can be collected.
You'll probably find it easier to construct states on demand, although I know others have more experience in this regard than I