[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Deferring __gc of userdata?
- From: Patrick Donnelly <batrick@...>
- Date: Wed, 28 Mar 2012 20:38:59 -0400
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