Article View: borland.public.jbuilder.java.swing
Article #11835JDialog remains allocate memory
From: Laurent Kubanski
Date: Thu, 01 Apr 1999 00:00
Date: Thu, 01 Apr 1999 00:00
97 lines
2965 bytes
2965 bytes
Hi,
I execute inside a JFrame them operations :
- From JFrame : Create JDialog
- From JDialog : Delete JDialog (with dispose())
The consequence is all JDialog remains allocate memory (no passage in the
garbage collector)
For information, if JDialog deleted with system closing (cross highly right)
is ok.
Thanks for your help.
PS: Sample
import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;
public class MyFrame extends JFrame implements ActionListener
{
public MyFrame()
{
super("MyFrame");
getContentPane().setLayout(new GridLayout(1, 2));
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e) {System.exit(0);}
});
JButton button1 = new JButton("OPEN DIALOG");
button1.addActionListener(this);
button1.setActionCommand("OPEN DIALOG");
getContentPane().add(button1);
JButton button2 = new JButton("RUN GC");
button2.addActionListener(this);
button2.setActionCommand("RUN GC");
getContentPane().add(button2);
pack();
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand().equals("OPEN DIALOG"))
{
new MyDialog(this);
}
else if (e.getActionCommand().equals("RUN GC"))
{
System.runFinalization();
System.gc();
}
}
public static void main(String arg[])
{
Runtime.runFinalizersOnExit(true);
new MyFrame();
}
}
class MyDialog extends JDialog implements ActionListener
{
public MyDialog(Frame frame)
{
super(frame, "MyDialog", true);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent evt)
{
dispose();
}
});
setSize(300,100);
setLocation(100,100);
JButton button = new JButton("CLOSE DIALOG");
button.addActionListener(this);
button.setActionCommand("CLOSE DIALOG");
getContentPane().add(button, BorderLayout.CENTER);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
dispose();
}
protected void finalize() throws Throwable
{
System.out.println("dialog.finalize : " + this);
super.finalize();
}
}
Technical Details
Message-ID:
<7dv658$f4d$1@minus.oleane.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,55ef3b93b05afa2c,start X-Google-Attributes: gid111d45,public From: "Laurent Kubanski" <lkubanski@quartz-system.fr> Subject: JDialog remains allocate memory Date: 1999/04/01 Message-ID: <7dv658$f4d$1@minus.oleane.net> X-Deja-AN: 461469773 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 X-Complaints-To: abuse@oleane.net X-Trace: minus.oleane.net 922950632 15501 62.160.166.95 (1 Apr 1999 07:10:32 GMT) Organization: Guest of OLEANE NNTP-Posting-Date: 1 Apr 1999 07:10:32 GMT Newsgroups: borland.public.jbuilder.java.swing