lua-users home
lua-l archive

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


> 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