lua-users home
lua-l archive

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


* Mike Pall:

> However, if you want to implement finalizers, you'll still need to
> keep track of finalizable objects somehow or, as a last resort,
> check _every_ object whether it's finalizable/dead/finalized in
> each GC phase. Segregating userdata would be a simple solution.
> But that's pointless when you have to support __gc for tables,
> too, since tables make up the majority of traversable objects.

I'm pretty sure that you need this machinery anyway, once a table (or
function or coroutine) is used as a weak key or value in another
table.

Often, finalization is implemented using a designated weak table, and
objects are queued for finalization when those weak references are
cleared.  I'm not aware of any Lua peculiarity which would prevent
rescuing the object at this point for passing it to a finalizer.