lua-users home
lua-l archive

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


Am 22.05.2014 00:11 schröbte Coda Highland:
On Wed, May 21, 2014 at 3:07 PM, Philipp Janda <siffiejoe@gmx.net> wrote:
Am 21.05.2014 21:04 schröbte Tim Hill:


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.


Good point. The wording is definitely ambiguous (given that Lua uses a
_mark_ and sweep collector) and should be cleared up in the manual.

I'm not certain I agree. This feels like an implementation detail and
formalizing it as a required behavior carries a smell to me. My
opinion is the opposite -- the documentation should be removed to
avoid asserting any sort of guarantee about the behavior, since not
every Lua implementation is going to necessarily have the same
behavior as PUC-Rio Lua.

This guarantee is documented since at least Lua 5.0 [1][2]. The only thing that changed (and introduced the ambiguity in the manual) is the emphasis on "marking for finalization" instead of "object construction". Of course we could remove this guarantee, but this will make binding certain libraries difficult.


/s/ Adam


Philipp

  [1]: http://www.lua.org/manual/5.0/manual.html#2.9.1
  [2]: http://www.lua.org/manual/5.1/manual.html#2.10.1