lua-users home
lua-l archive

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



On Aug 23, 2013, at 5:59 PM, Tangent 128 <tangent128@gmail.com> wrote:

function t()
   local a = {}
   w[1] = a
   cg() cg()

   local a = 2
   cg() cg()
end

This is really a side-effect of the non-optimizing Lua compiler; a quick look at luac output shows that each "a" gets a different stack slot, since the compiler does not perform scope analysis (hardly surprising).

However, this does bring up an interesting issue for locals declared at the top-level scope in a long-lived script; as the earlier poster noted, these shadowed items will indeed live on until the script terminates so far as I can see.

local a = { a_very_big_table }
local a = 10
-- The table is now inaccessible but reachable by the GC

Of course, the quick answer is "don't do this", so I guess it might be worth noting somewhere in the Lua docs or wiki?

--Tim