lua-users home
lua-l archive

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

> One other issue with finalizers to be aware of is that if you store a
> userdata object as the key in a weak-keyed table (e.g., to track a set of
> objects), it will remain in the table after being finalized and won't get
> removed until it is actually collected.

Very well put. But notice that this behavior is intentional. Sometimes,
userdata may need to refer to data associated to itself through weak
tables in its finalizer.

Again, a safe approach is to make the userdata know when it has been
finalized and behave appropriately. For instance, file handles in
Lua can be checked with io.type whether they were already closed

-- Roberto