lua-users home
lua-l archive

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


Excerpts from Tim Hill's message of 2014-05-03 20:09:31 +0200:
> If I understand your design correctly, a better approach is not to release the reference on the userdata until you are sure that it is truly no longer needed.
Candid reply, indeed. As I said, it is evil. The problem with your
suggestion is what happens when one does not have control over
"when it is no longer needed".

Typically, in user code, the correct pattern is to clone the object
being finalized. Unfortunately this is not possible if object contains
indeterminate state which is impossible to clone since it depends
on state of entirely different VM (typically cannot move memory
location).

Both Java and .NET supports explicit re-request for finalization
exactly for this purpose (ReRegisterForFinalization)

The idea is to simply detect the point when last reference is gone
(in a VM i can make no assumptions about), anchor the object and
set up finalizer for object on the other side (so when both are
gone _then_ you finally release it). There are various mid-states
of resurrection, but generally this is the only way to manage
liveness of objects linked to another tracing GC (refcounting
is simpler, but cyles...).