lua-users home
lua-l archive

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



On May 20, 2014, at 6:49 PM, Philipp Janda <siffiejoe@gmx.net> wrote:

They are collected in the reverse order that they were marked for finalization[1] (usually by setting the metatable), so B will always be collected before A if both become garbage at the same time, because it was created/marked last.


I’m not sure this is true; the Lua docs say “in the reverse order they were marked for COLLECTION” (not finalization). So my reading is that the order depends entirely on the order in which the GC determines objects to be unreachable, and (in my reading of it at least) I don’t see a clear guarantee of that ordering in the docs.

In any case, imho it’s very bad to depend on the ordering of finalizer calls in any garbage-collected language. If you really have two objects that depend on finalizer ordering then I think you really have a single dispose function that cleans up BOTH at once and can be called from either finalizer, which is much more robust.

—Tim