lua-users home
lua-l archive

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


> Sent: maandag 8 oktober 2012 9:27
> 
> > Marc Balmer <marc@msys.ch> schreef:
> > The 5.1 refrence manual says about garbage collecting userdata:
> >
> > "At the end of each garbage-collection cycle, the finalizers for
> > userdata are called in reverse order of their creation, among those
> > collected in that cycle. That is, the first finalizer to be called is
> > the one associated with the userdata created last in the program. The
> > userdata itself is freed only in the next garbage-collection cycle. "
> >
> > But this does not imply that the __gc field is called twice, right?
> > I.e. the __gc field of any userdata value is called exactly only
> once,
> > is that correct?
> >
> > Thanks,
> > Marc
> 
> Yep. 1st calls gc method, 2nd frees the ud.
> 
> Iirc there is an exception with os.exit() that might cause the gc
> method not being called.
> 
> Thijs

Just looked up the os.exit() in the ref manual, and it differs for 5.1 / 5.2

For 5.1:
--------
> os.exit ([code])
> Calls the C function exit, with an optional code, to terminate 
> the host program. The default value for code is the success code. 

For 5.2:
--------
> os.exit ([code [, close])
> Calls the C function exit to terminate the host program. If code 
> is true, the returned status is EXIT_SUCCESS; if code is false, 
> the returned status is EXIT_FAILURE; if code is a number, the 
> returned status is this number. The default value for code is true. 
> 
> If the optional second argument close is true, closes the Lua state 
> before exiting. 

For __gc to run the Lua state must be closed as mentioned with the 5.2 os.exit(). What isn't mentioned is what Lua state is being closed, but I would assume only the current state. Some clarification in the manual would be nice.