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

Dialogs are never garbage collected

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      rc1
    • CPU:
      x86
    • OS:
      windows_98, windows_2000
    • Verification:
      Verified

      Description



      Name: bsC130419 Date: 08/22/2001


      java version "1.4.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b65)
      Java HotSpot(TM) Client VM (build 1.4.0-beta-b65, mixed mode)


      I imagine this is already fixed in your internal betas, but just in case...

      Dialogs in the 1.4 beta never become garbage collectable. Conveniently, the
      1.4 beta also won't let me use hprof, so I can't trace the pointer chain and
      figure out why.

      The following test case demonstrates the problem:

      ---

      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();
              dialog2.dispose();
              
              // show Dialog3
              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);
          }
      }

      ---

      It works fine in JDK 1.3.1. In JDK 1.4 beta, only Dialog1 is ever finalized.
      This means that any dialog box which is ever shown (or even packed) can never
      become garbage collectable, leading to a huge memory leak.
      (Review ID: 130385)
      ======================================================================

      I tried the attached new sample program with 1.4.0fcs, this issue seems
      to happen.

      1. Reproducing

       1) Compile the new sample program(Fd2.java)
       2) Invoke "java Fd2"
          -> you will see a frame which has "Show Child Dialog" and "Cancel"
             buttons.
       3) Click the "Show Child Button"
          -> you will see a frame which has "File Dialogue" and "Cancel"
             buttons.
       4) Click the "File Dialogue"
          -> you will see a file dialogue for file selection.
       5) Click the "Cancel" button in the file dialogue which appeared
          at the 4) opearation.
       6) Click the "Cancel" button on the frame which appeared at 3).
          -> you will be aware that you returns 2).
       7) Repeat from 2) to 6) for many times.
       8) Finally, you will see the following messages in the command prompt
          window and opration freezed.

      total=66650112byte,free=3621592byte
      total=66650112byte,free=2014104byte
      total=66650112byte,free=1974888byte
      total=66650112byte,free=367736byte
      total=66650112byte,free=328968byte
      java.lang.OutOfMemoryError
      total=66650112byte,free=291808byte
      java.lang.OutOfMemoryError


      2. Configration

        MPU: Pentium IV 1.4[GHz]
        Mem: 384[MB]
        OS : Windows2000 SP2 (Japanese)
        JDK: 1.4.0fcs

      java version "1.4.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
      Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

      3. Note
        - I attached an image file(leak.jpg) which shows how the memory becomes
          short as a sample.
          This is the result with OptimizeIt4.11.
        - How many time should we repeat the 2)-6) loop in the above process ?
          It depends on each platform.
          With my PC, I repeated 50 times or so.

      2002-03-26
      ================================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              ssisunw Ssi Ssi (Inactive)
              Reporter:
              bstrathesunw Bill Strathearn (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: