lua-users home
lua-l archive

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

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?