JDK-4384267 : Regression: Finalize is not called for cloned objects.
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 1.3.0
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2000-10-30
  • Updated: 2012-10-08
  • Resolved: 2000-12-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other Other
1.3.1 betaFixed 1.4.0Fixed
Related Reports
Relates :  
Description

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

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: ladybird FIXED IN: ladybird INTEGRATED IN: ladybird-beta merlin-beta
14-06-2004

WORK AROUND Name: rmT116609 Date: 10/30/2000 none ======================================================================
11-06-2004

SUGGESTED FIX Make register_finalizer a static member of instanceKlass so it's available outside of the class. Call register_finalizer from JVM_Clone. Did other cleanups while I was in there. Files: update: src/share/vm/prims/jvm.cpp (1.411) update: src/share/vm/oops/instanceKlass.cpp (1.216) update: src/share/vm/oops/instanceKlass.hpp (1.123)
11-06-2004

EVALUATION In JVM_Clone, we're not registering the newly created object for finalization. jane.loizeaux@East 2000-12-01
01-12-2000