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);
}
}
}
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);
}
}
}
- duplicates
-
JDK-6354655 JDialog memory not released when created from popup menu
- Closed
- relates to
-
JDK-6240100 PIT:Reg testcase awt/Component/ComponentLeakTest/ComponentLeakTest.html fails from mustang b24
- Closed