Index: core/windows/src/org/netbeans/core/windows/services/NbPresenter.java =================================================================== RCS file: /shared/data/ccvs/repository/core/windows/src/org/netbeans/core/windows/services/NbPresenter.java,v retrieving revision 1.26 diff -u -r1.26 NbPresenter.java --- core/windows/src/org/netbeans/core/windows/services/NbPresenter.java 25 Nov 2005 09:15:40 -0000 1.26 +++ core/windows/src/org/netbeans/core/windows/services/NbPresenter.java 6 Dec 2005 08:46:11 -0000 @@ -154,6 +154,7 @@ } private void initialize(NotifyDescriptor d) { + setDefaultCloseOperation (WindowConstants.DISPOSE_ON_CLOSE); //Optimization related to jdk bug 4393857 - on pre 1.5 jdk's an //extra repaint is caused by the search for an opaque component up //to the component root. Post 1.5, root pane will automatically be Index: core/windows/test/unit/src/org/netbeans/core/windows/services/DialogDisplayerImplTest.java =================================================================== RCS file: /shared/data/ccvs/repository/core/windows/test/unit/src/org/netbeans/core/windows/services/DialogDisplayerImplTest.java,v retrieving revision 1.4 diff -u -r1.4 DialogDisplayerImplTest.java --- core/windows/test/unit/src/org/netbeans/core/windows/services/DialogDisplayerImplTest.java 15 Sep 2005 20:10:23 -0000 1.4 +++ core/windows/test/unit/src/org/netbeans/core/windows/services/DialogDisplayerImplTest.java 6 Dec 2005 08:46:11 -0000 @@ -15,13 +15,18 @@ import java.awt.Dialog; import java.awt.EventQueue; +import java.lang.ref.Reference; +import java.lang.ref.WeakReference; +import java.lang.reflect.InvocationTargetException; import javax.swing.JButton; +import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.SwingUtilities; import org.netbeans.junit.NbTestCase; import org.openide.DialogDescriptor; import org.openide.DialogDisplayer; import org.openide.NotifyDescriptor; +import org.openide.util.RequestProcessor; /** * @@ -36,6 +41,8 @@ private JButton openChild; private JButton closeChild; private Dialog child; + private Dialog testDialog; + private Dialog swingDialog; public DialogDisplayerImplTest (String testName) { super (testName); @@ -209,6 +216,63 @@ assertFalse ("Leaf is dead", owner.isVisible ()); assertFalse ("Child is dead too", child.isVisible ()); + } + + /** Tests issue 55273: Dialogs created by DialogDisplayer are not disposed after close + * + * @throws java.lang.Exception + */ + public void testDialogDisposed () throws Exception { + final DialogDescriptor dd = new DialogDescriptor (pane, "Hello", false, new Object[] {closeOwner}, null, 0, null, null); + //final DialogDescriptor dd = new DialogDescriptor (new JLabel ("Hello"), "Hello", false, null); + testDialog = DialogDisplayer.getDefault().createDialog(dd); + Reference ref = new WeakReference (testDialog); + SwingUtilities.invokeAndWait (new Runnable () { + public void run () { + testDialog.setVisible (true); + } + }); + assertNotNull ("Test dialog lives.", ref.get ()); + SwingUtilities.invokeAndWait (new Runnable () { + public void run () { + closeOwner.doClick (); + } + }); + while (testDialog.isVisible ()); + assertNotNull ("Test dialog still lives.", ref.get ()); + testDialog.dispose(); + testDialog = null; + RequestProcessor.getDefault ().post (new Runnable () { + public void run () { + } + }, 1000).waitFinished (); + assertGC ("Test dialog allocs no resources.", ref); + assertNull ("Test dialog must be dead.", ref.get ()); + } + + public void testSwingDialogDisposed () throws Exception { + swingDialog = new Dialog ((Dialog)null, "Hello"); + Reference ref = new WeakReference (swingDialog); + SwingUtilities.invokeAndWait (new Runnable () { + public void run () { + swingDialog.setVisible (true); + } + }); + assertNotNull ("Test dialog lives.", ref.get ()); + SwingUtilities.invokeAndWait (new Runnable () { + public void run () { + swingDialog.setVisible (false); + } + }); + while (swingDialog.isVisible ()); + assertNotNull ("Test dialog still lives.", ref.get ()); + swingDialog = null; + RequestProcessor.getDefault ().post (new Runnable () { + public void run () { + } + }, 1000).waitFinished (); + assertGC ("Test dialog allocs no resources.", ref); + assertNull ("Test dialog must be dead.", ref.get ()); } private void postInAwtAndWaitOutsideAwt (final Runnable run) throws Exception {