Name: rmT116609 Date: 10/30/2000
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
Java HotSpot(TM) Client VM (build 1.3.0, mixed mode)
The attached (trivial) code demonstrates the problem.
When this code is run under JDK1.3, the finalize method of Cell is never called.
It appears as if Cell objects are being garbage collected since otherwise the
program would quickly exhaust memory.
When run under JDK1.2.2_06, the finalize method is called frequently.
class TestClone {
public static void main(String[] args) {
int count = 0;
Cell primary = new Cell();
Cell copy = null;
while (true) {
copy = (Cell)primary.clone();
copy.modify();
if ((++count % 10000) == 0) {
System.out.println("Created " + count + " cells.");
System.gc();
}
}
}
private static class Cell implements Cloneable {
private byte[] data_ = new byte[5000];
public void modify() {
data_ = new byte[2000];
}
public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException e) {
System.out.println("Cannot clone");
}
return null;
}
protected void finalize() throws Throwable {
super.finalize();
System.out.println("cell finalized");
}
}
}
(Review ID: 111547)
======================================================================