Thread GC problem
kaffe@rufus.w3.org
kaffe@rufus.w3.org
Tue, 25 Aug 1998 09:25:27 -0700
You are correct that the thread won't really get destroyed without
super.finalize(), However, even sticking that line in the threads do not
get finalized (the Collecting xxx message is never printed). Do you get
the Collecting xxx message when you run it.
Godmar Back <gback@cs.utah.edu> on 08/25/98 12:05:36 AM
Please respond to kaffe@rufus.w3.org
To: kaffe@rufus.w3.org
cc:
Subject: Re: Thread GC problem
>
> breed@almaden.ibm.com writes:
> > Are the threads being garbage collected properly? I can't really see
where
> > the dead threads are getting garbage collected, The finalizer doesn't
seem
> > to be called on a dead thread, and the # of thread contexts keep
> > increasing. My observations are based on running the following
program:
> >
> > import java.util.Random;
> > class gctest extends Thread {
> > static Random r = new Random();
> > byte b[];
> > public void run() {
> > b = new byte[r.nextInt() & 0xff];
> > System.out.println( "all done" );
> > }
> > protected void finalize() { System.out.println( "Collecting " + this
); }
>
> This may or may not have anything to do with it, but "finalize"
> should written as:
>
> protected void finalize() {
> System.out.println( "Collecting " + this );
> super.finalize();
> }
>
Archie is right, it did have to do with it:
Kaffe was falsely relying on the proper behavior of thread's subclasses,
i.e., that they call super.finalize(); Obviously, no such assumption can
be made.
The fix is to remove the finalizer method from java.lang.Thread()
and to invoke finalizeThread directly from finalizeObject instead.
- Godmar