Clearing a table by re-assignment?

Hello all,
This should be a simple question. Assume I have the following table:

local container = {}

Later, I add sub-tables to this table, as follows:

container[#container+1] = {}  -- assume this new inserted table ID is "0x1b5bed00"

So from a structural standpoint, the table would look like this:

container = { {} } OR... container = { table: 0x1b5bed00 }

Now my question is, when I go about ending my level, I want to clear the contents of this "container" table, but I want to keep the table itself in memory because it will be used again. Can I effectively clear this table by simply saying?

container = {}

Will that basically reset the container table to a new ID and free up the reference of the sub-table(s) that I added to it earlier, so those sub-tables (display objects, in my case) can be garbage-collected?

I think this works... testing seems to indicate so... but I'd like to confirm that this "short-hand" method is 100% effective by Lua standards. I know that I could loop through the container table using "table.remove" or similar, but if the simple re-assignment method that I outlined does the same thing, then I'd prefer to use that.

Thanks!
Brent Sorrentino
Ignis Design

No, I think that assigns a brand new table which will ultimately result in the whole old table to be garbage collected.

Also, watch out for the length operator (i.e. #container). It only does what you think it does for arrays.

views:1482 update:2011/10/5 21:23:48
corona forums © 2003-2011