Damien Neil wrote: > Using object lifetime to control state is almost never a good idea, > even if you have deterministic finalization. A much better approach > is to have methods which allow holders of the object to control it, > and a finalizer (DESTROY method) which cleans up only if necessary. > > A more real-world case is IO::Handle. If you want to close a handle > explicitly, you call $handle->close, not $handle->DESTROY. The > concept of closing a handle is orthogonal to the concept of the object > ceasing to exist. User code can close a handle. It can't make the > object go away -- only the garbage collector can do that. I think you just said all about why we shouldn't bother giving objects deterministic finalization, and I agree with you. If we explicitly want to free resources (files, database connections), then we explicitly call close. Otherwise, it will be called when DESTROY is eventually called. - Branden
- Re: Garbage collection (was Re: JWZ on s/Java/Perl/) Damien Neil
- Re: Garbage collection (was Re: JWZ on s/Java/Perl/) Simon Cozens
- Re: Garbage collection (was Re: JWZ on s/Java/Perl/) Damien Neil
- Re: Garbage collection (was Re: JWZ on s/Java/Perl/) Hong Zhang
- Re: Garbage collection (was Re: JWZ on s/Java/Perl/) Branden
- Re: Garbage collection (was Re: JWZ on s/Java/Perl/) Tim Bunce
- Re: Garbage collection (was Re: JWZ on s/Java/Perl/) Branden
- Re: Garbage collection (was Re: JWZ on s/Java/Perl/) Uri Guttman
- Re: Garbage collection (was Re: JWZ on s/Java/Perl/) Tim Bunce
- Re: Garbage collection (was Re: JWZ on s/Java/Perl/) Uri Guttman
- Re: Garbage collection (was Re: JWZ on s/Java/Perl/) Branden
- Re: Garbage collection (was Re: JWZ on s/Java/Perl/) Damien Neil
- Re: Garbage collection (was Re: JWZ on s/Java/Perl/) Branden
- Re: Garbage collection (was Re: JWZ on s/Java/Perl/) Alan Burlison
- Re: Garbage collection (was Re: JWZ on s/Java/Perl/) Hong Zhang
- Re: Garbage collection (was Re: JWZ on s/Java/Perl/) Alan Burlison
- Re: Garbage collection (was Re: JWZ on s/Java/Perl/) Hong Zhang
- Re: Garbage collection (was Re: JWZ on s/Java/Perl/) Alan Burlison
- Re: Garbage collection (was Re: JWZ on s/Java/Perl/) Ken Fox
- Re: Garbage collection (was Re: JWZ on s/Java/Perl/) Hong Zhang
- Re: Garbage collection (was Re: JWZ on s/Java/Perl/) Ken Fox