lua-users home
lua-l archive

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


On 08/23/2013 05:40 AM, Leo Razoumov wrote:
> No, garbage collector will collect the t
Actually, a quick experiment:

> w = setmetatable({}, {__mode="kv"})
> function cg()
>     collectgarbage()
>     for k,v in pairs(w) do
>         print(k,v)
>     end
>     print"---"
> end
> function t()
>     local a = {}
>     w[1] = a
>     cg() cg()
>
>     local a = 2
>     cg() cg()
> end
>
> cg()
> t()
> cg()

shows that the local continues to prevent garbage collection as long as
it's on the stack (that is, until t() returns), even if it's lexically
shadowed.

~Joseph Wallace