JDK-6233069 : JOptionPane.createDialog leaks resources
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 5.0,6
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: generic,windows_xp
  • CPU: generic,x86
  • Submitted: 2005-02-25
  • Updated: 2011-02-16
  • Resolved: 2006-04-28
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.5.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Windows XP

A DESCRIPTION OF THE PROBLEM :
Using JOptionPane.createDialog to construct a dialog for displaying results in the embedded component not being GC'ed when the dialog is dismissed.  If you embed the same component within a JOptionPane.showMessageDialog you do not get a leak.

(Leak also exist in 1.4.2_02)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the following program and attach your favorite profiler to it.  Count how many JLabels are left...

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Number of JLabels shoud be 0 (zero)
ACTUAL -
Number of JLabels was 10 (ten)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.swing.*;

public class Option
{
  public static void main(String[] args) throws Throwable
  {
    // give yourself time to run profiler
    System.out.println("attach profiler now...");
    Thread.sleep(5000);
    System.out.println("running app...");

    // these JLabels don't get GC'ed :(
    for(int i = 0; i < 10; i++)
    {
      JLabel goodbye = new JLabel("Goodbye " + i);
      JOptionPane op = new JOptionPane(goodbye, JOptionPane.PLAIN_MESSAGE);
      JDialog d = op.createDialog(null, "Goodbye");
      d.setVisible(true);
      op = null;
      d = null;
      goodbye = null;
    }

    // these JLabels GC correctly
    for(int i = 0; i < 10; i++)
    {
      JLabel hello = new JLabel("Hello " + i);
      JOptionPane.showMessageDialog(null, hello, "Hello", JOptionPane.PLAIN_MESSAGE);
    }
  }
}



---------- END SOURCE ----------
###@###.### 2005-2-25 08:49:08 GMT

Comments
EVALUATION The problem described in this bug is not reproducible, if Dialog is gc'ed, JLabed is also gc'ed, see bug 4726458 which explains why some of Dialogs are not garbage collected
28-04-2006

EVALUATION Contribution-Forum:https://jdk-collaboration.dev.java.net/servlets/ProjectForumMessageView?messageID=11470&forumID=1463
16-02-2006