Thread GC problem

Godmar Back kaffe@rufus.w3.org
Tue, 25 Aug 1998 01:05:36 -0600 (MDT)


> 
> 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