lua-users home
lua-l archive

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

Seems like that settles it. They will all go away after the function returns, so may as well just create them all. The function is recursive, but I only expect it to go half a dozen levels or so, and I can put a do/end around the locals before the recursion. Thanks.

On Wed, Jan 2, 2013 at 9:23 AM, Roberto Ierusalimschy <> wrote:
> Every distinct variable you allocate needs to be de-allocated by the
> garbage collector once it goes out of scope. So if you declare a dozen
> variables, that is a dozen objects the GC needs to mark and collect. If you
> declare two variables  and re-use them with objects of the same type, thats
> only two variables to mark and collect.

Local variables in Lua are not dynamic entities: they are not allocated
(and not deallocated). When a function starts, it gets the space for all
local variables it will need from the stack, an array that more often
than not have space spare for them. So, the cost of "creating" local
variables is virtually zero in Lua.

-- Roberto