JDK-4682912 : Out of Memory occurrs because FileDialogs are not GCed
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2002-05-10
  • Updated: 2002-05-24
  • Resolved: 2002-05-24
Related Reports
Duplicate :  
Relates :  
Description
Filedialogs do not seem to be GCed.
So, when we invoke and close FileDialogs many times, too much memory
is consumed and the VM freezes.

1. Reproducing

 1) Compile the new sample program(Fd2.java)
 2) Invoke "java Fd2"
    -> you will see a frame which has "Show Child Dialog" and "Cancel"
       buttons.
 3) Click the "Show Child Button"
    -> you will see a frame which has "File Dialogue" and "Cancel"
       buttons.
 4) Click the "File Dialogue"
    -> you will see a file dialogue for file selection.
 5) Click the "Cancel" button in the file dialogue which appeared 
    at the 4) opearation.
 6) Click the "Cancel" button on the frame which appeared at 3).
    -> you will be aware that you returns 2).
 7) Repeat from 2) to 6) for many times.
 8) Finally, you will see the following messages in the command prompt 
    window and opration freezed.

total=66650112byte,free=3621592byte
total=66650112byte,free=2014104byte
total=66650112byte,free=1974888byte
total=66650112byte,free=367736byte
total=66650112byte,free=328968byte
java.lang.OutOfMemoryError
total=66650112byte,free=291808byte
java.lang.OutOfMemoryError


2. Configration

  MPU: Pentium IV 1.4[GHz]
  Mem: 384[MB]
  OS : Windows2000 SP2 (Japanese)
  JDK: 1.4.0fcs, 1.4.1-beta-b11

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)

D:\>java -version
java version "1.4.1-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-beta-b11)
Java HotSpot(TM) Client VM (build 1.4.1-beta-b11, mixed mode)


3. Note 
  - I attached an image file(leak.jpg) which shows how the memory becomes 
    short as a sample.
    This is the result with OptimizeIt4.11.
  - How many time should we repeat the 2)-6) loop in the above process ?
    It depends on each platform.
    With my PC, I repeated 50 times or so.
  - The Memory usage becomes 64[MB]( by watching the graph of optimizeit), 
    this issue happpens.

2002-05-10
==============================================================================

Comments
EVALUATION Commit to fix in mantis (memory leak).
11-06-2004

SUGGESTED FIX Here is suggested fix for this issue. I tried it for 1.4.0fcs and built bin. The binary worked well for the attached test program. Please evaluate the fix whether or not there is any problem other than the attached sample code. ===> *** awt_FileDialog.cpp-bkup Tue Feb 12 08:09:08 2002 --- awt_FileDialog.cpp Thu May 9 19:39:10 2002 *************** *** 185,190 **** --- 185,191 ---- AwtFileDialog::fileFilterID); if (!JNU_IsNull(env,fileFilter)) { ofn.Flags |= OFN_ENABLEINCLUDENOTIFY; + env->DeleteLocalRef(fileFilter); } ofn.lCustData = (DWORD)peer; ofn.lpfnHook = (LPOFNHOOKPROC)FileDialogHookProc; *************** *** 244,249 **** --- 245,259 ---- delete[] fileBuffer; delete[] directoryBuffer; delete[] titleBuffer; + env->DeleteLocalRef(target); + if(NULL != parent) + env->DeleteLocalRef(parent); + if(NULL != directory) + env->DeleteLocalRef(directory); + if(NULL != title) + env->DeleteLocalRef(title); + if(NULL != file) + env->DeleteLocalRef(file); throw; } *************** *** 251,256 **** --- 261,275 ---- delete[] fileBuffer; delete[] directoryBuffer; delete[] titleBuffer; + env->DeleteLocalRef(target); + if(NULL != parent) + env->DeleteLocalRef(parent); + if(NULL != directory) + env->DeleteLocalRef(directory); + if(NULL != title) + env->DeleteLocalRef(title); + if(NULL != file) + env->DeleteLocalRef(file); } BOOL <=== ###@###.### 2002-05-10 ============================================================================
10-05-2002