JDK-6936389 : FontManager.fileCloser may cause memory leak in applets
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 6
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2010-03-19
  • Updated: 2011-01-19
  • Resolved: 2010-04-12
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.
JDK 6 JDK 7
6u21 b03Fixed 7Fixed
Related Reports
Relates :  
Description
FontManager creates fileCloser to be executed at shutdown. 

In applet environment this may be triggered from the application context and then contextClassLoader will be refering to applet's classloader.
This prevents classes loaded by this classloader from being unloaded (and their static state!) until thread is disposed. 

However, in plugin same VM is reused for other apps and shutdown hook may be not be called for long period of time.

For FX applet this may cause leak of 10-20Mb depending on what applet was run first.

Here is the example of reference chains from the memory dump:

System Class Reference :
--> class sun.font.FontManager (84 bytes) (static field fileCloser:)
--> java.lang.Thread@0x281c3f70 (104 bytes) (field contextClassLoader:)
--> sun.plugin2.applet.JNLP2ClassLoader@0x27f08078 (136 bytes) (field classes:)
--> java.util.Vector@0x27f1bd10 (24 bytes) (field elementData:)
--> [Ljava.lang.Object;@0x283241e0 (5128 bytes) (Element 200 of [Ljava.lang.Object;@0x283241e0:)
--> class reversi.Main (84 bytes) (static field $titleImage:)
--> javafx.scene.image.ImageView@0x2814a7c0 (466 bytes) (field $platformImage:)
--> java.awt.image.BufferedImage@0x27f9a208 (37 bytes) (field raster:)
--> sun.awt.image.IntegerInterleavedRaster@0x27f9acf8 (101 bytes) (field dataBuffer:)
--> java.awt.image.DataBufferInt@0x27f9bde8 (36 bytes)

System Class Reference :
--> class java.lang.ApplicationShutdownHooks (84 bytes) (static field hooks:)
--> java.util.IdentityHashMap@0x27f14ec8 (36 bytes) (field table:)
--> [Ljava.lang.Object;@0x27f35fa8 (264 bytes) (Element 18 of [Ljava.lang.Object;@0x27f35fa8:)
--> java.lang.Thread@0x281c3f70 (104 bytes) (field contextClassLoader:)
--> sun.plugin2.applet.JNLP2ClassLoader@0x27f08078 (136 bytes) (field classes:)
--> java.util.Vector@0x27f1bd10 (24 bytes) (field elementData:)
--> [Ljava.lang.Object;@0x283241e0 (5128 bytes) (Element 200 of [Ljava.lang.Object;@0x283241e0:)
--> class reversi.Main (84 bytes) (static field $titleImage:)
--> javafx.scene.image.ImageView@0x2814a7c0 (466 bytes) (field $platformImage:)
--> java.awt.image.BufferedImage@0x27f9a208 (37 bytes) (field raster:)
--> sun.awt.image.IntegerInterleavedRaster@0x27f9acf8 (101 bytes) (field dataBuffer:)
--> java.awt.image.DataBufferInt@0x27f9bde8 (36 bytes)

Comments
EVALUATION The essence of fix is exactly same as for similar problems in java.util.LogManager and javax.imageio.stream (CRs 6799583 and 6788096). A thread instance used as a shutdown hook keeps a reference to an applet classloader and prevents applet's resources releasing. Suggested solution is to clear the shutdown hook's context classloader. Except this, a main thread group is used for creation of the shutdown hook, in order to prevent potential failure of the hook's execution (see CR 6222850). There is yet another long leaving thread which may lock the applet classloader: it is sun.java2d.Disposer. Their context classloader is also cleared by the fix.
05-04-2010

SUGGESTED FIX http://sa.sfbay.sun.com/projects/java2d_data/6u20/6936389.0
05-04-2010

EVALUATION Similar to what was done for 6799583 we can reset contextClassLoader to null at the creation time.
19-03-2010