lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


 On 18/09/2010 02:26, jgiors@threeeyessoftware.com wrote:
<--- snip --->

Sorry I wasn't clear about it. Anyway, the short answer is "Yes."

Long answer: Actually, the script code will be collected independent of
using t in main.lua. Keep in mind that loadfile() turns the text script
into a function. There isn't anything special about it being a script vs
a function defined by some other means.

Here's what happens:

1. loadfile( 'get_t.lua' ) compiles the script and places an anonymous
function on the stack.
2. The function is called via the parens () on that same line.
3. That function returns t, and t copied into the "local t" of main.lua.
4. When that line completes, the function is popped off the stack.

At this point the function is no longer referenced. It and it's bytecode
are ready to be garbage collected.

OTOH, if your concern is about the reliability of Lua's GC, I don't
think that is an issue.
Nope, just if the bytecode would be collected. get_t.lua will create some tables and user data (but won't create any global) and I wanted to be sure it would be available for garbage collection after not being referenced since t has a very short lifetime in main.lua.

Thanks,

Andre
Hope that makes more sense.


John Giors
Independent Programmer
Three Eyes Software
jgiors@ThreeEyesSoftware.com
http://www.ThreeEyesSoftware.com