lua-users home
lua-l archive

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


>>>>> "Gé" == Gé Weijers <ge@weijers.org> writes:

 Gé> - It's not clear to me what the use case is for changing the
 Gé> metatable in a finalizer to begin with. In the normal case you'd
 Gé> expect the object to be unreachable after the finalizer returns, so
 Gé> it will be freed in the next pass.

When dealing with userdatas in particular, it can be useful to reset the
metatable in the finalizer to nil or to a dummy metatable, because there
is a specific case where the object is _NOT_ unreachable after the
finalizer returns: if it's a key in an ephemeron table. (The ephemeron
table entry is not removed until the object is collected on the next
pass; so it's important that either the __gc method for a userdata
leaves the object data in a state that won't crash in the event of
further access to the object, or that it removes or replaces the
metatable.)

-- 
Andrew.