lua-users home
lua-l archive

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


2008/9/8 Joe Gester <joe@muzzylane.com>:
> I have several full userdatas with metatables and a __gc metamethod
> implemented in C.  Storing the userdata in a global variable, I can access
> its members and call other metamethods like __index and __newindex as
> exoected.  If my script assigns nil to the global variable, the __gc method
> runs.  If I assign nil to the variable from C and use lua_gc to collect the
> garbage or call lua_close, the __gc method does not run.

How do you "assign nil to the variable from C" ?

> Should __gc called when the references are broken from outside the script
> and/or when lua_close is run?  Is there something in particular I ought to
> be doing to get __gc to run?  I would expect it to just work since garbage
> is properly collected when the references are broken from within the script.

All gc metamethods should be called when you call lua_close. When
using lua_gc, it may require several full collection cycles to get
your userdata collected.