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

JFrame instances are not garbage collected upon disposal

    XMLWordPrintable

Details

    • x86, sparc
    • linux, solaris_7, solaris_8, windows_nt

    Description

      On JVM 1.3.0, 1.3.1 and 1.4, JFrame instances are not garbage collected upon disposal.
      Exception occurred during event dispatching:
      java.lang.OutOfMemoryError
              <<no stack trace available>>

      ================================================================================
      To reproduce problem
      -Compile SimpleFrame.java and JFrameBug.java
      - execute JFrameBug
      - on the "JFrameBug Test" window choice "Open Frame" to Start program:

      Program failed with this message "Exception occurred during event dispatching:
      java.lang.OutOfMemoryError
              <<no stack trace available>>"

      ==============================================================================
      Files following

      file SimpleFrame.java
      -------------------


      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;


      public class SimpleFrame extends JFrame{

        public SimpleFrame() {
          setSize(600, 600);
          JPanel panel = new JPanel();
          JButton openButton = new JButton("Ouvrir");
          JButton closeButton = new JButton("Fermer");
          openButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              SimpleFrame s = new SimpleFrame();
              s.show();
            }
          });
          closeButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              dispose();
            }
          });
          for (int i=0; i<50; i++) {
            panel.add(new JLabel("Simple Frame - "));
          }
          panel.add(openButton);
          panel.add(closeButton);
          getContentPane().add(panel);
        }
      }


      file JFrameBug.java
      -------------------
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;

      public class JFrameBug extends JFrame {
        JPanel contentPane;
        JMenuBar jMenuBar1 = new JMenuBar();
        JMenu jMenuFile = new JMenu();
        JMenuItem jMenuFileOpenFrame = new JMenuItem();
        JMenuItem jMenuFileExit = new JMenuItem();
        BorderLayout borderLayout1 = new BorderLayout();

        /**Construct the frame*/
        public JFrameBug() {
          enableEvents(AWTEvent.WINDOW_EVENT_MASK);
          try {
            jbInit();
          }
          catch(Exception e) {
            e.printStackTrace();
          }
          show();
        }
        public static void main(String[] args) {
          JFrameBug JFramBug1 = new JFrameBug();

        }

        private void jbInit() throws Exception {
          //setIconImage(Toolkit.getDefaultToolkit().createImage(JFrameBug.class.getRe
      source("[Your Icon]")));
          contentPane = (JPanel) this.getContentPane();
          contentPane.setLayout(borderLayout1);
          this.setSize(new Dimension(800, 600));
          this.setTitle("JFrameBug Test");
          jMenuFile.setText("File");
          jMenuFileExit.setText("Exit");
          jMenuFileOpenFrame.setText("Open Frame");
          jMenuFileExit.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              jMenuFileExit_actionPerformed(e);
            }
          });
          jMenuFileOpenFrame.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              jMenuFileOpenFrame_actionPerformed(e);
            }
          });
          jMenuFile.add(jMenuFileOpenFrame);
          jMenuFile.add(jMenuFileExit);
          jMenuBar1.add(jMenuFile);
          this.setJMenuBar(jMenuBar1);
        }
        /**File | Exit action performed*/
        public void jMenuFileExit_actionPerformed(ActionEvent e) {
          System.exit(0);
        }
        /**File | Start Tests action performed*/
        public void jMenuFileOpenFrame_actionPerformed(ActionEvent e) {
          for (int i=0; i<1200;i++) {
            SimpleFrame s = new SimpleFrame();
            s.show();
            s.dispose();
          }
        }
        /**Overridden so we can exit when window is closed*/
        protected void processWindowEvent(WindowEvent e) {
          super.processWindowEvent(e);
          if (e.getID() == WindowEvent.WINDOW_CLOSING) {
            jMenuFileExit_actionPerformed(null);
          }
        }
      }

      Attachments

        Issue Links

          Activity

            People

              dav Andrei Dmitriev (Inactive)
              duke J. Duke
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: