[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Re[2]: state of the Lua nation on resource cleanup
- From: Mark Hamburg <mark@...>
- Date: Sun, 31 May 2009 15:49:46 -0700
I think this really comes down to two cases:
1. You know the lifetime for the object and you can explicitly close
it when done -- e.g., by calling f:close(). f:close() is much clearer
that the goal is to close the resource. f = nil just means "I don't
care about this particular reference to the resource anymore".
2. You don't know the lifetime. Then you are looking to the system to
find all of the potentially live references and the only way to do
that with absolute certainty is to complete a full GC. Reference
counting won't get it for you because of cycles. Now, maybe the
objects you are interested in -- e.g., file handles -- can't be
directly involved in cycles, but the objects referencing them -- e.g.,
tables -- could be.
One could patch the Lua VM so that assignments adjusted reference
counts and this would result in some items getting collected faster,
but it would not ensure that all objects would get finalized the
moment they became unreachable because that's a problem that requires
global rather than local information.
This is not unique to Lua. The languages that seem to give one
immediate collection do so by restricting the data structures one can
build or by expecting the programmer to restrict the choice of data
structures and/or how they are used.
Mark
- References:
- Re: state of the Lua nation on resource cleanup, Cosmin Apreutesei
- Re: state of the Lua nation on resource cleanup, Roberto Ierusalimschy
- Re: state of the Lua nation on resource cleanup, David Manura
- Re: state of the Lua nation on resource cleanup, Cosmin Apreutesei
- Re[2]: state of the Lua nation on resource cleanup, Bulat Ziganshin
- Re: Re[2]: state of the Lua nation on resource cleanup, David Manura
- Re: Re[2]: state of the Lua nation on resource cleanup, Cosmin Apreutesei
- Re: Re[2]: state of the Lua nation on resource cleanup, Matthew Wild
- Re: Re[2]: state of the Lua nation on resource cleanup, Cosmin Apreutesei
- Re: Re[2]: state of the Lua nation on resource cleanup, Peter Cawley
- Re: Re[2]: state of the Lua nation on resource cleanup, Cosmin Apreutesei