lua-users home
lua-l archive

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


Am 22.05.2014 08:05 schröbte Eric Wing:
I don't think that anyone has mentioned this yet, but I guess you mean
something like this:
*   put B in A's uservalue table to keep it alive as long as A is alive
*   put a weak back reference to A in B's uservalue table
*   in A's finalizer free A if it hasn't been freed before by someone else
*   in B's finalizer first free A if the weak back reference still
exists and A hasn't been freed before, and then free B itself if it
hasn't been freed before

One thing I noticed is that the uservalue table of my objectA being
finalized in the _gc callback still has a reference to objectB, even
if objectB's _gc callback was invoked before this one. (I suppose this
is for if you need resurrection?)

Unless I mixed up A and B, A's uservalue table is supposed to hold strong references to B, and strong references are never cleared from a table. B should have a weak uservalue table with references to A, but you can't say exactly when the references are cleared (Lua 5.2 at least says whether it will happen before or after A's finalizer).


Philipp