United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6936389 FontManager.fileCloser may cause memory leak in applets
JDK-6936389 : FontManager.fileCloser may cause memory leak in applets

Details
Type:
Bug
Submit Date:
2010-03-19
Status:
Resolved
Updated Date:
2011-01-19
Project Name:
JDK
Resolved Date:
2010-04-12
Component:
client-libs
OS:
generic
Sub-Component:
2d
CPU:
generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:
6u21 (b03)

Related Reports
Backport:
Relates:

Sub Tasks

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

Similar to what was done for 6799583 we can reset contextClassLoader to null at the creation time.
                                     
2010-03-19
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.
                                     
2010-04-05
SUGGESTED FIX

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



Hardware and Software, Engineered to Work Together