JDK-6301795 : JFileChooser causes memory leak
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2005-07-26
  • Updated: 2011-02-16
  • Resolved: 2006-07-21
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05)

ADDITIONAL OS VERSION INFORMATION :
Windows XP SP2

A DESCRIPTION OF THE PROBLEM :
Using the JFileChooser not frees memory on Windows side (Taskmanager).
The path which JFileChooser browses contains about 20'000 Files.
So everytime the JFileChooser is used on this path the used memory grows up about 20MB and is never released until the Java application terminates.
No references on the JFileChooser exists.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. JFileChooser fc = new JFileChooser(path);
2. fc.showOpenDialog(parent);

path is a directory contains about 20'000 files.
parent is the calling component.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
After the JFileChooser is closed, memory will be released.
ACTUAL -
Memory on Windows side (Taskmanager) is never released, grows up to several hundred MB.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class Test {
  /**
     * Shows memory leak on windows.
     * @param args args[0] -> Path to a directory contains a lot of files (eg 20'000).
     */
    public static void main(String[] args) {
        String path = args [0];
        JFrame parent = new JFrame();
        for (int i = 0; i < 5; i++) {
            JFileChooser fc = new JFileChooser(path);
            fc.showOpenDialog(parent);
        }
        System.exit(0);
    }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Use native FileDialog from AWT package.

Comments
EVALUATION This is NOT memory leak, but massive usage of resources. The following command was used to test from description: java -Xmx32m -verbose:gc Test c:\20k
13-07-2006