[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: __gc finalizer called at exit?
- From: Rob Kendrick <lua-l@...>
- Date: Tue, 11 Dec 2007 20:31:50 +0000
On Tue, 2007-12-11 at 16:28 -0200, Roberto Ierusalimschy wrote:
> > I've scrutinized the reference manual and also done some web searching,
> > and nowhere do I find the answer to this question: if Lua exits
> > either by a call to os.exit or by a normal return from the main chunk,
> > does it guarantee to call the __gc finalizers for any live userdata objects?
> No and yes. The 'lua' applicative calls lua_close before returning,
> and so clears everything. A call to os.exit skips that closing. We
> thought about adding lua_close in an atexit function, but leaved as
> it is so there is a way to skip lua_close if needed. (This may speed
> up some programs which finish with lots of data to clean up.)
Would using atexit() be reliable? It's tricky to use usefully in
complex applications because you don't get to provide an arbitrary void
* to pass to your function, there's a limited number of available slots
in most libc implementations, and semantics get messy when you think
about things like exec(). I'm sure there are many other issues, too :-/
Perhaps have os.exit() take a flag that controls if objects should be
collected before exit() is called?