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

Reply via email to