I want to share my experience of garbage collection of the Java virtual
machine.

There are two common types of garbage collection, the agressive reference
count based and everything else.

The reference count system can garantee the quick response to memory
release. In such a system, we can safely use DESTROY or ~Object() to
release system resources.

For real garbage collection systems, there is no garantee when the
finalize()
method will be called. Many system does not even garantee they will ever
be called. For example, when exit() is called, the garbage collection will
not even have chance to run. The other common cases, if you open 10,000
file objects, and does not use much memory space otherwise, the garbage
collection will be not triggered since so little memory is used.

The only solution will be use try {} finally {} construct, and the virtual
machine
will also remember all the system resource it is holding, such as files,
sockets,
memories. When exit() is called, the virutal machine will free everything by
itself without calling back to Perl or Java. This is the same the Unix
operating
system does when process calls exit() or abort().

>From my personal experience with Java, the finalize() will never exist. Any
program that relies on it will fail one way or another. I have seen many
applications have to be rewritten to avoiding using finalize(). Explicit
release
system resource is always safe and recommended.

The downside is you have to always write things like.
  my $fh = IO::File->open("foo", "w");
  try {
  } finally {
    $fh->close();
  }

Hong

----- Original Message -----
From: "Graham Barr" <[EMAIL PROTECTED]>
To: "Dan Sugalski" <[EMAIL PROTECTED]>
Cc: "Branden" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Wednesday, February 14, 2001 12:29 PM
Subject: Re: Please shoot down this GC idea...


> On Wed, Feb 14, 2001 at 03:04:40PM -0500, Dan Sugalski wrote:
> > At 05:57 PM 2/14/2001 -0300, Branden wrote:
> > >Simon Cozens wrote:
> > > > On Wed, Feb 14, 2001 at 11:38:58AM -0800, Damien Neil wrote:
> > > > >   sub do_stuff { ... }
> > > > >
> > > > >   {
> > > > >     my $fh = IO::File->new("file");
> > > > >     do_stuff($fh);
> > > > >   }
> > > > >
> > > > > In this code, the compiler can determine that $fh has no active
> > > > > references at the end of the block
> > > >
> > > > No, it can't, but it can certainly put a *test* for not having
references
> > > > there.
> >
> > Yes it can tell, actually--we do have the full bytecode to the sub
> > available to us, along with whatever metainfo we choose to remember
> > generally about the sub. Whether we use the info is a separate matter,
of
> > course.
>
> Not if the sub is AUTOLOADed
>
> Graham.

Reply via email to