lua-users home
lua-l archive

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


on 7/5/06 10:33 AM, Jerome Vuarand at jerome.vuarand@ubisoft.com wrote:

> So the problem is that once my finalizer is called it's never called again,
> but I still have references to the object. Is that normal ? Since after the
> finalizer call I have access to my object in the global scope, what prevents
> me from calling methods on it ? In fact I've tested it with a slightly more
> complex object, and methods get passed an invalid object. Methods that will
> misbehave if I don't detect myself if the object I'm getting has already been
> finalized or not.
> 
> I don't mind getting an answer like "storing references to an object in its
> finalizer is forbidden", provided it's official (like explicitly stated in the
> manual). But even in that cases it sounds a bit scary (fortunately it's not
> possible to reproduce the case with pure lua).

The semantics of the __gc metamethod are that it will be called the first
time the object becomes inaccessible. (Well, actually, the first time it is
detected to be inaccessible.) The object itself won't be collected until it
is both inaccessible and it's __gc metamethod if any has been called.

Mark