[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: finalizer call order in GC cycle during lua_close (Lua 5.2)
- From: Richard Hundt <richardhundt@...>
- Date: Sat, 30 Jan 2010 21:13:38 +0100
Hi List,
I'm seeing __gc finalizers on userdata objects being called in an
unexpected order when a Lua state is closed.
I have a buffer udata which holds a reference to a file descriptor udata
in its associated environment table. During a *normal* GC cycle (run via
collectgarbage() from Lua), the buffer's __gc metamethod runs before
that of the fd, as I'd expect since at this point the fd is still
reachable via the buffer's fenv.
At program termination, though, I'm getting the reverse, which I find
surprising. It means I can't flush buffer to the file handle during the
buffer's __gc at normal program termination, since the fd is already
collected by then, despite the fact that it's still reachable.
Is there a rationale for this, or some way to tame it?
Thanks.
-Rich