develooper Front page | perl.perl6.internals | Postings from February 2001

Re: Garbage collection (was Re: JWZ on s/Java/Perl/)

Thread Previous | Thread Next
From:
Branden
Date:
February 15, 2001 02:06
Subject:
Re: Garbage collection (was Re: JWZ on s/Java/Perl/)
Message ID:
OE76TRqf69aZbLAX3cf000072de@hotmail.com
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


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About