[gclist] A Java question.

stuart stuart@cosc.canterbury.ac.nz
Sun, 30 Mar 1997 17:48:34 +1200


 
> And if you do, this has no bearing on the eventual invocation 
> caused by the normal GC built-in mechanism which will also 
> invoke finalize() exactly once [more]. 

Should this not read "which may also invoke" ?

My understanding is that java.lang.{System,Runtime}.exit() is
doesn't perform garbage collection before termination of the 
VM, nor does an uncaught Error or Exception.

That, at least, is the behaviour of the 'java version "1.1_Final"'
implementation, when presented with the following code, and there
doesn't appear to be anything in the standard in the topic.

stuart

import java.lang.System;
import java.lang.Error;
import java.lang.Object;

class Test extends Object{
  public static void main(String argv[]){
    System.runFinalizersOnExit(true);   // tell the VM to run finalisers

    Test aTest = new Test();            // our Test object
    Error t = new Error();              // an Error to throw

    System.out.println("aTest created - " + aTest);

    //aTest = null;                      // remove the reference to aTest

    //System.gc();                       // run the garbage collector
    //System.runFinalization();          // run the finaliser

    //System.exit(-1);                   // halt the VM
    throw t;                           // throw an Error
  }

  protected void finalize() throws Throwable{
    System.out.println("In finaliser now");
  }
}

-- 
         stuart yeates <stuart@cosc.canterbury.ac.nz> aka `loam'
                  you are a child of the kernel space 
            no less than the daemons and the device drivers,
                   you have a right to execute here.