Front page | perl.perl6.language |
Postings from August 2001
From: Hong Zhang
August 28, 2001 11:32
Message ID: 400CE9390E334A4393CEECDD6863120A28A017@ussccm003.corp.palm.com
> On Tue, Aug 28, 2001 at 09:13:25AM -0400, Michael G Schwern wrote:
> > As the pendulum swings in the other direction you get
> > silly things like finalize which I just learned of today.
> What's so silly about finalize? It's pretty much identical to Perl's
> DESTROY. (Except that Java's non-refcounting GC doesn't provide the
> same guarantees on when an object whill be finalized.) (And
> the problem
> that all too many JVMs have had buggy implementations of finalizers...
> that's an implementation issue, not a language one, though.)
The finalization is significantly different from DESTROY and destructor.
The problem is there is no guarantee the finalization method will be ever
called, or when it is called. For example, shall we let exit() to call all
finalization methods. It is very likely to cause deadlock. I don't think
C++ will unwind all thread stacks and call destructors in this case.
Most of finalization is used to deal with external resource, such as open
file, socket, window. You don't really want to depend on finalization,
since it is very likely run out of default file descriptor limit before
the finalization kicks in. The rule of thumb is to let finalization to
cleanup resource when an unexpected exception happens. It is more like
a safe-net or parachute. It is most likely to help you in emergency, but
there is no guarantee it will work.
by Hong Zhang