JDK-4195507 : Large Memory Leak with JDK 1.2fcs
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 1.2.0,1.2.1
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,windows_nt
  • CPU: generic,x86
  • Submitted: 1998-12-07
  • Updated: 2013-11-02
  • Resolved: 1999-01-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.2.2 1.2.2Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
I've modified the SwingMark benchmark program to track memory usage.  Under jdk 1.1.7 it seems OK, but under jdk 1.2 fcs it seems to leak like crazy.  To find the SwingMark benchmark you can look in:

/home/wilsonsd/SwingMarks

When run with the correct command line options, SwingMark will create a text file which shows memory usage.  Here is some sample output (along with the command line args to generate it).

java SwingMark -q -r 15 -m 117memory.txt

SwingMark Memory Report

Date: Thu Dec 03 16:10:27 PST 1998
JDK Version: 1.1.7B
JDK Vendor: Sun Microsystems Inc.
JDK Directory: e:\jdk1.1.7\bin\..
VM Info: Undefined
OS: Windows NT version 4.0
Video Bit-Depth: 16 Bits

Used Memory	HeapSize
784288	1134584
1031912	1388536
1277448	1703928
1031840	1986552
1032656	1986552
1033136	1986552
1033744	1986552
1033856	1986552
1033872	1986552
1033856	1986552
1033888	1986552
1034072	1986552
1033888	1986552
1034712	1986552
1033840	1986552
1033896	1986552
1034344	1986552
1034288	1986552
1034200	1986552
1034816	1986552

Here is the same report with JDK 1.2 fcs:

SwingMark Memory Report

Date: Thu Dec 03 16:20:44 PST 1998
JDK Version: 1.2
JDK Vendor: Sun Microsystems Inc.
JDK Directory: e:\jdk1.2fcsV\jre
VM Info: Classic VM build JDK-1.2-V, native threads, symcjit
OS: Windows NT version 4.0
Video Bit-Depth: 16 Bits

Used Memory	HeapSize
3066768	5660664
3702424	6787064
4329824	7917560
4960104	7995384
5593184	9125880
6223680	10252280
6854552	11382776
7487048	12513272
8126992	13639672
8752608	14770168
9384176	14847992
10013432	15978488
10643864	18153464
11273976	18235384
11903768	19361784
12534024	20496376
13163064	21626872
13792160	21708792
14424128	22839288
15068568	23965688

As you can see the 117 version starts using 700k and grows to about 1 meg.  The 1.2 version starts using 3 meg and grows to 15 meg.  The 1.2 version will grow until all memory is consumed.  It doesn't seem to level out.

steve.wilson@eng

-------------------------------------------

After working on this with Jim Graham, I've reduced the test case to a very small program.  Here it is:

-------------------------------------
import java.awt.*;
import javax.swing.*;

class FrameBash {

   public static void main(String[] args) {
      for (int i = 0; i < 20; i++) {
         Frame f = new JFrame();
         //          Frame f = new Frame();
         f.pack();
         f.setVisible(true);
         f.setVisible(false);
         f.dispose();
         System.gc();
      } 
      System.gc();  // beat the hell out of gc to make sure it happens
      for (int j = 0; j < 5; j++) {
         try {
            Thread.sleep(250);
         } catch (Exception e) {
            e.printStackTrace();
         }
         System.gc();
         System.runFinalization();
      }
      System.exit(0);
   }
}
----------------------------------

Looking at this with the -Xhrof option on the compiler, we find that none of these JFrames are ever GC'd.  After tracing through the references it appears that there is an InputMethod pointing to a JRootPane which points to a JFrame.  The InputMethod eventually winds up in a static list, which prevents GC.  It seems this happens on Win32, but perhaps not Solaris.  That needs to be looked into further.

This looks very similar to bug ID# 4193032.
steve.wilson@eng 1999-01-06

==============================================================================
Customer does not believe this bug has actually been fixed.  See information
added to 4193022.


sheri.good@Eng 1999-03-23

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: generic FIXED IN: 1.2.2 INTEGRATED IN: 1.2.2
14-06-2004

EVALUATION It looks like the memory arrays for the offscreen images are not being freed. Further investigation will be needed to see if this is due to a dangling reference in the AWT, Swing, or the 2D API. My first guess would be Swing, but I will need to construct a smaller test case first to check on this. Note that this leak could also exist under 1.1.x, but since the memory for off screen images is created by the platform graphics API and not in the Java heap, then the leak would not show up using the Java memory status methods. It would only show up by examining the C heap usage of the process or the memory consumption of the System (i.e. the X11 server for Solaris or the GDI resources for Windows). jim.graham@Eng 1999-01-04 [xueming.shen@Japan 1999-01-08] I just fixed bug#4180832 (plan to putback into jdk1.2.2 "C " next week) which also has effect to this bug, the memory result of running the SwingMark against the new binary (with the fix) is attached. And I have also checked the -Xhrof result of FrameBash class by using the hat tool, looks to me the InputMethod related leak is gone, most JFrame/JRootPane objects got GCed. So I reassign this back to the previous Resp.Engineer/Manager for further investigation <REPORT> <NAME>SwingMark</NAME> <DATE>Fri Jan 08 12:14:19 JST 1999</DATE> <VERSION>internal_build</VERSION> <VENDOR>Sun Microsystems Inc.</VENDOR> <DIRECTORY>h:\florida\export1\ws\jdk122\build\win32</DIRECTORY> <VM_INFO>Classic VM build internal_build, native threads, symcjit</VM_INFO> <OS>Windows NT version 4.0</OS> <BIT_DEPTH>15</BIT_DEPTH> Used Memory HeapSize 2122584 4308984 2738040 4390904 3353264 5513208 3967352 6635512 4585216 7761912 5199208 8888312 5816856 10010616 6430072 10088440 7044168 12263416 7665096 13389816 8278856 13467640 8892032 14594040 9506488 15720440 10119408 16846840 10733128 16924664 </REPORT> ------------------------------- I just ran the SwingMarks with the Memory option for 1.2.2-c promoted build. I got this result: <REPORT> <NAME>SwingMark</NAME> <DATE>Sun Jan 17 15:31:58 PST 1999</DATE> <VERSION>1.2.2</VERSION> <VENDOR>Sun Microsystems Inc.</VENDOR> <DIRECTORY>e:\jdk1.2.2-C\jre</DIRECTORY> <VM_INFO>Classic VM build JDK-1.2.2-C, native threads, symcjit</VM_INFO> <OS>Windows NT version 4.0</OS> <BIT_DEPTH>16</BIT_DEPTH> Used Memory HeapSize 3094848 5677048 3711440 6803448 3721200 6832120 3721440 6832120 3721488 6832120 3722712 6832120 3726480 6832120 3729136 6836216 3729016 6836216 3729040 6836216 3730584 6836216 3729408 6836216 3729440 6836216 3729456 6836216 3729536 6836216 </REPORT> This is a quite acceptible result. It is somewhat strange that it differs from Xueming Shen's run. I suspect that another leak was fixed and put-back for this build. Together they eliminated the problem. The leak seems to have been reduced from over 600k per run to less than 1k per run. We'll eventually want to track down that last k-byte, but I'm going to make this bug as fixed! Ye-ha! steve.wilson@eng 1999-01-17
17-01-1999