Been working with Lua for a little while now and didn't really ponder the concept of garbage collection until now.
If we have the following:
local table = {a, b, c}
So the variable 'table' is just a reference to {a, b, c} and not actually a table.
So next, If we do this:
table = {4, 5, 6}
'table' is now referenced to {4, 5, 6} with reference to {a, b, c} lost. {a, b, c} will be garbage collected as any object not referenced will be collected, correct?
So, the last line in the following loop is not needed, correct?
local table
for i = 1, 100 do
table = makeSomeTable() -- Some function that returns a unique table
---[[ Use table in some manner here ]]---
---[[ Use table in some manner here ]]---
---[[ Use table in some manner here ]]---
table = nil <<----- pointless correct???
end
Or is there a benefit to nil for garbage collection?
Comments
I'm using your expression in my projects because
"Before Older versions of Lua created empty tables with some pre-allocated slots to avoid this overhead when initializing small. However, this approach wastes memory".
As an example, the next loop runs in 2.0 seconds:
If you want know how garbage collection works check this thread
http://giderosmobile.com/forum/discussion/1423/class-inheritance-and-memory/p1
I hope I've helped you
P.S. samples was took of http://www.lua.org/gems/sample.pdf
Likes: ar2rsawseen
[-] Liasoft