Thread GC problem

breed at almaden.ibm.com breed at almaden.ibm.com
Tue Aug 25 09:25:27 PDT 1998


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 at cs.utah.edu> on 08/25/98 12:05:36 AM

Please respond to kaffe at rufus.w3.org

To:   kaffe at rufus.w3.org
cc:
Subject:  Re: Thread GC problem





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







More information about the kaffe mailing list