Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4726458

Dialogs and Frames are never garbage collected

XMLWordPrintable

    • b17
    • x86
    • windows_98, windows_2000
    • Not verified

        Name: rmT116609 Date: 08/05/2002


        FULL PRODUCT VERSION :
        C:\temp\bug>java -version
        java version "1.4.1-beta"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-beta-b14)
        Java HotSpot(TM) Client VM (build 1.4.1-beta-b14, mixed mode)

        FULL OPERATING SYSTEM VERSION :
        Microsoft Windows 2000 [Version 5.00.2195]

        A DESCRIPTION OF THE PROBLEM :
        Attached is sample code that causes a memory leak under 1.3 and 1.4.1. This sample adds one line of code to the already closed bug 4495338.

        This bug is causing us to have a major memory leak in our application.

        This bug also causes Frames and Dialogs to keep the JVM from exiting once all the frames are closed and disposed.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        1. javac TestCase.java
        2. java TestCase

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        Expected:
        Dialog1 being finalized
        Dialog2 being finalized
        Dialog3 being finalized

        Got:
        Dialog1 being finalized
        Dialog2 being finalized


        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import javax.swing.*;

        class TestDialog extends JDialog {
            String name;
            public TestDialog(String name) {
                this.name = name;
            }
            public void show() {
                super.show();
                dispose(); // so no user interaction is needed
            }
            public void finalize() {
                System.out.println(name + " being finalized");
            }
        }


        public class TestCase {
            public static void main(String[] arg) {
                TestDialog dialog1 = new TestDialog("Dialog1");
                TestDialog dialog2 = new TestDialog("Dialog2");
                TestDialog dialog3 = new TestDialog("Dialog3");

                // do nothing to Dialog1

                // pack Dialog2
                dialog2.pack(); //this is empty size 0,0
                dialog2.dispose();

                // show Dialog3
                dialog3.setSize(200,200); //added this line
                dialog3.show();

                // should be garbage collectable after this
                dialog1 = null;
                dialog2 = null;
                dialog3 = null;

                for (int i = 0; i < 20; i++)
                    System.gc();

                System.exit(0);
            }
        }
        ---------- END SOURCE ----------

        CUSTOMER WORKAROUND :
        Use no more than one JFrame or JDialog in your application.
        (Review ID: 160375)
        ======================================================================

              son Oleg Sukhodolsky (Inactive)
              rmandalasunw Ranjith Mandala (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: