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
[import]uid: 9747 topic_id: 12643 reply_id: 312643[/import]

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.

[import]uid: 7563 topic_id: 12643 reply_id: 46332[/import]