lua-users home
lua-l archive

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

In article
   Matthew Wild <> wrote:
> On 23 September 2011 21:40, Michael Gerbracht <> wrote:
> > If I put everything into one table and try the same:
> >
> > TableMain = {}
> > TableMain.A = {<many entries>}
> > TableMain.B = {<many entries>}
> > TableMain.C = {<many entries>}
> >
> > TableMain.B = nil
> >
> > then the memory is not garbage collected by lua. I hope this is correct so
> > far.

> I think you are confusing garbage collection with the shrinking of tables.
> They are unrelated. An object (such as a table) is collected when there are
> no references to it. Your large table will be collected when you replace it
> with nil, regardless of whether it was in a variable or a table.

> In summary, don't worry about it. The space used by unrecovered table slots
> is negligible and rarely worth worrying about. Your actual data will always
> be garbage collected when not accessible.

Ok, thank you very much! I had in mind that I read somewhere that a table can
only be garbage collected as a whole. But I guess it was only related to the
table slot as you explained which can be neglected due to its small amount.