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

JFrame does not call finalize in all cases

XMLWordPrintable

      FULL PRODUCT VERSION :
      jdk-1_5_0_08-windows-i586-p.exe
      java version "1.5.0_08"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_08-b03
      Java HotSpot(TM) Client VM (build 1.5.0_08-b03, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      XP2 SP2 all patches as of 22/09/06

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      IDE: Eclipse Build id: M20060629-1905

      A DESCRIPTION OF THE PROBLEM :

      In a JFrame window using the X in the top of the window results in the 'finalize' method being called.

      BUT.. when I try to close the window via a button, the 'finalize' method doesn't get called and it sits in memory. argh!

      Have tested with the following JDK's

      Code works with...
      j2sdk-1_4_2_11-windows-i586-p.exe
      jdk-1_5_0-windows-i586.exe
      jdk-1_5_0_04-windows-i586-p.exe
      jdk-1_5_0_06-windows-i586-p.exe
      jdk-1_5_0_07-windows-i586-p.exe

      FAILES WITH....
      jdk-1_5_0_08-windows-i586-p.exe

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run attached code.

      Click on button marked 'EXIT' and NO finalize statement is printed to system.out.

      Click on 'X' button in the top right and it does print out that the finalize method is called.

      Retest on previous JDK & it works. i.e. both X & 'EXIT' should print out that the finalize method is called.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      both X & 'EXIT' should print out that the finalize method is called.
      ACTUAL -
      Click on button marked 'EXIT' and NO finalize statement is printed to system.out.

      Click on 'X' button in the top right and it does print out that the finalize method is called.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      None


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class CloseTest extends JFrame {
       
      JButton button;
      String name;
       
      protected void finalize() throws Throwable {
      super.finalize();
      System.out.println("finalize + CloseTest:" + name);
      }

      public CloseTest(String name) {
      this.name = name;
      setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
      button = new JButton("EXIT:"+ name);
      button.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent e) {
      endEvent();
      }});
      addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
      end();
      }
      });
      getContentPane().add(button);
      pack();
      setVisible(true);
      }
       
      private void endEvent() {
      dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
      }

      private void end() {
      setVisible(false);
      dispose();
      }

      public static void main(String args[]) {

      new CloseTest("1");
      new CloseTest("2");
      new CloseTest("3");
      new CloseTest("4");
      new CloseTest("5");
      new CloseTest("6");
      new CloseTest("7");
      new CloseTest("8");
      new CloseTest("9");
      new CloseTest("0");

      System.out.println("ready");
       
      while(true) {
      try {
      Thread.sleep(500);
      System.gc();
      } catch (InterruptedException e) {
      }
      }
      }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Go back to the last JDK

      jdk-1_5_0_07-windows-i586-p.exe

      Release Regression From : 5.0u7
      The above release value was the last known release where this
      bug was not reproducible. Since then there has been a regression.

            bchristi Brent Christian
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: