-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.3.1
-
x86
-
windows_nt
Name: yyT116575 Date: 08/07/2001
java version "1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)
The following code leaks one instance of ZMemoryLeakWindow, but only when
opening the popup of the combobox. In our case, this means that everytime a
combobox is opened, the whole frame will not be garbage-collected, meaning that
virtually everything remains in memory.
just run test.gerd.ZMemoryLeak and press the Show-Frame button. This will open
a ZMemoryLeakWindow(LEAK-Window) which will allocate a lot of memory. If you
then press close in the LEAK-Window, everything gets garbage-collected. But if
you klick on the combobox before closing (opening the popup) the LEAK-Window
will not get garbage-collected.
(PS: I looked for similar bugs in the bug database, but found only bugs related
to popup-menus).
here's the code
********************************************************
package test.gerd;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class ZMemoryLeak extends JFrame {
public static void main(String[] args) {
new ZMemoryLeak().setVisible(true);
}
public ZMemoryLeak() {
super("MAIN");
getContentPane().setLayout(new BorderLayout());
getContentPane().add(createBtn(), BorderLayout.SOUTH);
setSize(800, 600);
setDefaultCloseOperation(3);
}
private void closeFrame() {
setVisible(false);
dispose();
}
private JComponent createBtn() {
JPanel p = new JPanel(new GridLayout());
JButton btn = new JButton("Show Frame");
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) {
new ZMemoryLeakWindow().setVisible(true);
}
});
p.add(btn);
return p;
}
}
***********************************************************
package test.gerd;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class ZMemoryLeakWindow extends JFrame {
public static void main(String[] args) {
new ZMemoryLeak().setVisible(true);
}
private char[] buff= new char[1024*1024*12];
public ZMemoryLeakWindow() {
super("LEAK-Window");
getContentPane().setLayout(new BorderLayout());
getContentPane().add(new JComboBox(), BorderLayout.NORTH);
getContentPane().add(createBtn(), BorderLayout.SOUTH);
setSize(800, 600);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
private void closeFrame() {
setVisible(false);
dispose();
}
private JComponent createBtn() {
JPanel p = new JPanel(new GridLayout());
JButton btn = new JButton("Close");
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) {
closeFrame();
}
});
p.add(btn);
return p;
}
}
(Review ID: 129476)
======================================================================
- duplicates
-
JDK-4352535 ToolTipManager still leaks in Metal L&F
- Resolved