Name: rm29839 Date: 06/12/98
Hi. I'm running jdk1.2beta3 on Solaris 2.5.1 on a Sparc machine.
I found this problem when running Source 3.22 on page 160 in the
Wiley book "Java 1.2 and Javascript for C and C++ Programmers."
In the beta JDK, the finalize() method doesnt run when I call
System.runFinalization(), but it does in JDK 1.1.5.
Here is the code:
// tstFinalize.java
package jwiley.chp3;
class simpleObject2
{
int a = 5;
void setA(int inA) {
System.out.println("Setting data member");
a = inA;
}
protected void finalize() {
System.out.println("Finalizing simpleObject");
a = 0;
}
}
class tstFinalize
{
public static void main(String args[]) {
simpleObject2 myObject = new simpleObject2();
myObject.setA(100);
myObject = null;
System.out.println("Garbage collecting");
System.gc();
System.out.println("Finalizing");
System.runFinalization();
}
}
In both cases I compiled the code with the JDK 1.2.beta3 version
of javac. When I enter "java jwiley.chp3.tstNative" to run with
the beta JVM, I get:
Setting data member
Garbage collecting
Finalizing
When I run the same class file with the JDK 1.1.5 version of
"java" I get:
Setting data member
Garbage collecting
Finalizing
Finalizing simpleObject
(Review ID: 33561)
======================================================================