lua-users home
lua-l archive

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


Thanks for the replies.  I'm curious...  how does the algorithm work?  How can Lua determine what does and doesn't need to be collected if it doesn't keep a reference count on an object?

For example, it's clear that, after the code I had shown earlier is run, that tables A and B are in their own little reference group, but then the same can be said of the table "mytableC = {}" right after it is created.  It's in its own little reference group, yet it shouldn't be garbage collected.

I should probably buy the book.  I'm starting to vaguely recall the idea of...

mytableD = {}
mytableD.refD = mytableD
mytableD = nil

...in reading the book.  Or look at the book online...


On Tue, Apr 29, 2014 at 10:57 PM, Andrew Starks <andrew.starks@trms.com> wrote:


On Tuesday, April 29, 2014, Spencer Parkin <spencertparkin@gmail.com> wrote:
Consider the following...

mytablaA = {}
mytableB = {}
mytableA.refB = mytableB
mytableB.refA = mytableA
mytableA = nil
mytableB = nil

There is no longer a reference to either table, yet they reference one another, so the tables are still around, right?  If so, will these tables never get garbage collected?

Lua does not use a reference counter for its GC and is able to avoid these issues. Since there is no path to these tables, they'll be collected.