lua-users home
lua-l archive

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


On Wed, Mar 28, 2012 at 5:40 PM, Graham Wakefield
<wakefield@mat.ucsb.edu> wrote:
> Short version:
> I feel like this should be possible, but would like to know for sure. Is it possible to re-reference a userdata during the __gc handler, to prevent the memory being reclaimed immediately?

Yes, this is known as "resurrecting" the userdata [1]. A key point is
the finalizer is only ever called once. For correctness, you should
consider what happens if a userdata finalizer is called on lua_close.
The memory will be freed by Lua whether you are ready or not.

[1] http://www.lua.org/manual/5.2/manual.html#2.5.1

-- 
- Patrick Donnelly