Is this is an efficient method of clearing a table’s data without any memory leaks?
local table={} -- add data for i=1,20 do table[i]="test" end -- clear table={}
thoughts?
Is this is an efficient method of clearing a table’s data without any memory leaks?
local table={} -- add data for i=1,20 do table[i]="test" end -- clear table={}
thoughts?
This doesn’t really clear any data. What you’re doing is creating two tables, and using the same variable to store a reference to the first table, then to the second.
However, if after the last line you have no more references to the first table or its contents, then the table and its contents will be candidates for garbage collection, which will eventually free up the memory.
First, never use “table” as a variable, it will trash the “table” object.
You should do:
myTable = nil
to remove the previous version of the table.
Rob
Thanks rob, and yes I know, it was more of an example.
This doesn’t really clear any data. What you’re doing is creating two tables, and using the same variable to store a reference to the first table, then to the second.
However, if after the last line you have no more references to the first table or its contents, then the table and its contents will be candidates for garbage collection, which will eventually free up the memory.
First, never use “table” as a variable, it will trash the “table” object.
You should do:
myTable = nil
to remove the previous version of the table.
Rob
Thanks rob, and yes I know, it was more of an example.