JDK-6788496 : JFileChooser.showOpenDialog leaks native memory on Windows
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6u10
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2008-12-23
  • Updated: 2011-01-19
  • Resolved: 2009-10-22
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_06"
Java(TM) SE Runtime Environment (build 1.6.0_06-b02)
Java HotSpot(TM) Client VM (build 10.0-b22, mixed mode, sharing)


ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
JFileChooser is still leaking native memory, even though bug 6301795 is closed and bug 6396844 is "fixed".

There is NO Java memory leak, as any Java profiler can tell. I have used very small -Xmx, -XX:MaxPermSize, and -XX:ReservedCodeCacheSize, and the Java program keeps running just fine, with profiler showing no memory increase after GC.

It is Windows native memory that's leaking. Windows resource kit's vadump shows the Java process memory usage increase is all in the native heap.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the test code, bring up Windows Task Manager (or a better process viewer like sysinternals Process Explorer).

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Memory usage (all types: working set, private size, etc.) should remain flat after file chooser dialog shows any number of times.
ACTUAL -
Memory usage keeps growing.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.EventQueue;
import java.io.File;

import javax.swing.*;

public class TestJFileChooser
{
    public static void main(String args[])
    {
        EventQueue.invokeLater(new Runnable()
        {
            public void run()
            {
                int n = 200;
                while(--n > 0)
                {
                    JFileChooser fileChooser = new JFileChooser();
                    fileChooser.setMultiSelectionEnabled(false);
                    fileChooser.setSelectedFile(new File("c:\\windows"));
                    fileChooser.setDialogType(JFileChooser.CUSTOM_DIALOG);
                    fileChooser.showOpenDialog(null);
                    System.out.println(n);
                }
                System.exit(0);
            }
        });

    }
}

---------- END SOURCE ----------