United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-4745575 1.4.0 REGRESSION: Windows GDI resource leak when using JFileChooser with Windows
JDK-4745575 : 1.4.0 REGRESSION: Windows GDI resource leak when using JFileChooser with Windows

Details
Type:
Bug
Submit Date:
2002-09-11
Status:
Resolved
Updated Date:
2002-10-18
Project Name:
JDK
Resolved Date:
2002-10-18
Component:
client-libs
OS:
windows_98,windows_xp,windows_2000
Sub-Component:
java.awt
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
1.4.0,1.4.1
Fixed Versions:
1.4.2 (mantis)

Related Reports
Duplicate:
Relates:
Relates:

Sub Tasks

Description

Name: jk109818			Date: 09/11/2002


FULL PRODUCT VERSION :
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]

ADDITIONAL OPERATING SYSTEMS :
WIN98 (and I guess on all windows platforms)


A DESCRIPTION OF THE PROBLEM :
The problem is that when using a JFileChooser with a
Windows L&F (WindowsFileChooserUI), there is a GDI resource
leak when traversing the filesystem. Whenever a new
directory is browsed, more GDI resources are consumed,
never to be released before the process terminates. The
JFileChooser dialog can be opened and closed many times,
but the leak remains and grows with each new directory that
is browsed. This bug DOES NOT exist if the
MetalFileChooserUI is used.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Simply run FileChooserDemo
2. Switch to Windows L&F
3. Open the dialog. With each new directory that is
browsed, more GDI resources are consumed (no new GDI
resources are consumed if you return to a directory that
you had already been in). This leak can be easily seen
with Windows' task manager, adding "GDI Objects" to the
viewed columns.
4. You may close and open the dialog several times and see
that the leak remains (with the task manager) until the
process terminates.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
Just run the FileChooserDemo that comes with the SDK, and follow the steps I
described before.
---------- END SOURCE ----------

CUSTOMER WORKAROUND :
The only workaround I can think of is using
MetalFileChooserUI instead of WindowsFileChooserUI. Of
course this is not a good one, since I want to see the
Windows L&F.
(Review ID: 163882) 
======================================================================

                                    

Comments
SUGGESTED FIX



Name: ssR10077			Date: 09/26/2002


*** /export3/ssi/mantis/webrev/src/windows/native/sun/windows/ShellFolder.cpp-	Thu Sep 
26 13:50:54 2002
--- ShellFolder.cpp	Thu Sep 26 13:41:12 2002
***************
*** 738,743 ****
--- 738,750 ----
      jintArray iconBits = env->NewIntArray(nBits);
      // Copy values to java array
      env->SetIntArrayRegion(iconBits, 0, nBits, colorBits);
+     // Fix 4745575 GDI Resource Leak
+     // MSDN 
+     // GetIconInfo creates bitmaps for the hbmMask and hbmColor members of ICONINFO. 
+     // The calling application must manage these bitmaps and delete them when they 
+     // are no longer necessary. 
+     ::DeleteObject(iconInfo.hbmColor);
+     ::DeleteObject(iconInfo.hbmMask);    
      return iconBits;
  }
  
***************
*** 804,809 ****
--- 811,819 ----
      jintArray bits = env->NewIntArray(numPixels);
      // Copy values to java array
      env->SetIntArrayRegion(bits, 0, numPixels, colorBits);
+     // Fix 4745575 GDI Resource Leak
+     ::DeleteObject(hBitmap);
+     ::FreeLibrary(libComCtl32);
      return bits;
  }
  
*** /export3/ssi/mantis/webrev/src/windows/native/sun/windows/awt_Dialog.cpp-	Thu Sep 
26 13:50:55 2002
--- awt_Dialog.cpp	Thu Sep 26 13:35:38 2002
***************
*** 39,44 ****
--- 39,51 ----
      if (m_modalWnd != NULL) {
  	WmEndModal();
      }
+     // Fix 4745575 GDI Resource Leak
+     // MSDN 
+     // Before a window is destroyed (that is, before it returns from processing 
+     // the WM_NCDESTROY message), an application must remove all entries it has 
+     // added to the property list. The application must use the RemoveProp function
+     // to remove the entries. 
+     ::RemoveProp(GetHWnd(), ModalDisableProp);
  }
  
  const char* AwtDialog::GetClassName() {

======================================================================
                                     
2004-06-11
EVALUATION

Will fix for next release.
###@###.### 2002-09-11

Name: ssR10077			Date: 09/27/2002


###@###.### 2002-09-27
Problem is inside src/windows/native/sun/windows/ShellFolder.cpp
Java_sun_awt_shell_Win32ShellFolder_getIconBits
calls GetIconInfo but doesn't release returned bitmaps

======================================================================
                                     
2004-06-11
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
mantis

FIXED IN:
mantis

INTEGRATED IN:
mantis
mantis-b04


                                     
2004-06-14



Hardware and Software, Engineered to Work Together