lua-users home
lua-l archive

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

On Mon, May 21, 2012 at 03:08:45PM +0530, forume wrote:
> Removed from virtual space and resource I meant of course. :-)
> If I had something like:
> t = {"string", "longdatastring", 10023841}
> Than "table.remove(t,2)" would really remove it so in virtual
> space/resources/memory I would really have:
> t = {"string", 10023841}
> Right? Or doesn't it even really do that?

You're confusing arrays and hash tables, both of which are available in
Lua using tables.

table.remove removes an entry from the array part, and moves things down
so you still have a contiguous ordered set.

Hash tables have no ordering, so there is no need for such a call, just
replace its value with nil.

The garbage collector will eventually free the memory consumed by the
old value, assuming it is safe to do so (ie, not used elsewhere.)