Re: Tables and memory saving
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Tables and memory saving
- From: Gé Weijers <ge@...>
- Date: 2011年9月23日 14:52:25 -0700 (PDT)
On 2011年9月23日, 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.
No it's not. You created a nested table, and the 'inner' table that
TableMain.B refers to will be collected sometime after you assign 'nil' to
TableMain.B, because there is no way to get to that table anymore. And
that's exactly the criterion used be the garbage collector to decide
whether the table can be removed.
Your examples use essentially the same amount of memory. You have three
large tables, and a 3-entry one referred to by TableMain. The difference
in memory use of all your examples is just a few table slots.
Gé