Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #5471

Re: Why is dispose() not working?

Newsgroups comp.lang.java.gui
Date 2015-06-11 14:41 -0700
References <JiXV5.23884$II2.2261972@newsread2.prod.itd.earthlink.net>
Message-ID <aa16b310-f698-4f44-ab14-80e074570eea@googlegroups.com> (permalink)
Subject Re: Why is dispose() not working?
From rathore.rohtash@gmail.com

Show all headers | View raw


On Saturday, December 2, 2000 at 5:54:13 AM UTC+5:30, Ross Mills wrote:
> Hi,
> 
> I have a simple JDialog with a single button.  An ActionListener was added
> to the button so that dispose() is called when the button is clicked.  Also,
> a WindowListener was added so that dispose() is called when then JDialog is
> closed.
> 
> Here is my problem:  When I close the JDialog by clicking on the X in the
> upper right hand corner, the JDialog disappears and the garbage collector
> reclaims the JDialog's resources.  However, when I close the JDialog by
> clicking on the button, the JDialog disappears but the JDialog's resources
> are NOT reclaimed by the garbage collector.  I continue to lose memory as I
> repeatedly display and close the JDialog.
> 
> Below is a very short example in which this problem can be reproduced:
> 
> I know I could work-around this problem by reusing the JDialog, but I really
> should not have to.  How can I free the resources for this JDialog when I
> click on the button?
> 
> Thanks,
> Ross Mills
> 
> 
> Here is the JDialog source code...
> 
> package TestDiag;
> 
> import com.sun.java.swing.*;
> import java.awt.event.*;
> 
> public class Diag extends JDialog {
>     JButton closeBtn = new JButton("Close");
> 
>     public Diag(JFrame parent) {
>         super(parent);
>         setModal(true);
>         closeBtn.addActionListener(new BtnListener());
>         addWindowListener(new WinListener());
>         getContentPane().add(closeBtn);
>         pack();
>         System.out.println("Built Diag");
>     }
> 
>     protected void finalize() throws Throwable {
>         System.out.println("Cleaning up Diag");
>     }
> 
>     class BtnListener implements ActionListener {
>         public void actionPerformed(ActionEvent e) {
>             dispose();
>         }
>     }
> 
>     class WinListener extends WindowAdapter {
>         public void windowClosing(WindowEvent e) {
>             dispose();
>         }
>     }
> }
> 
> 
> and here is the JFrame from which I call the above JDialog...
> 
> package TestDiag;
> 
> import com.sun.java.swing.*;
> import java.awt.event.*;
> 
> public class MainFrame extends JFrame {
> 
>     JButton goBtn = new JButton("GO");
> 
>     public MainFrame() {
>         goBtn.addActionListener(new BtnListener(this));
>         getContentPane().add(goBtn);
>         pack();
>     }
> 
>     class BtnListener implements ActionListener {
>         MainFrame mFrame;
> 
>         public BtnListener(MainFrame mFrame) {
>             this.mFrame = mFrame;
>         }
> 
>         public void actionPerformed(ActionEvent e) {
>             Diag diag = new Diag(mFrame);
>             diag.setVisible(true);
>             System.gc();
>         }
>     }
> 
>     static public void main(String args[]) {
>         (new MainFrame()).setVisible(true);
>     }
> }

My Jdialog is not closing on a single click if i am cancelling the jdialog from the upper right portion of the dialog that cross sign.how can i close it on single click

Back to comp.lang.java.gui | Previous | Next | Find similar


Thread

Re: Why is dispose() not working? rathore.rohtash@gmail.com - 2015-06-11 14:41 -0700

csiph-web