Memory leak of java.lang.ref.WeakReference objects inside JDK classes

Posted by mandye on Stack Overflow See other posts from Stack Overflow or by mandye
Published on 2010-03-23T05:11:06Z Indexed on 2010/03/23 5:11 UTC
Read the original article Hit count: 425

Filed under:
|
|

The following simple code reproduces the growth of java.lang.ref.WeakReference objects in the heap:

public static void main(String[] args) throws Exception {

while (true) { java.util.logging.Logger.getAnonymousLogger(); Thread.sleep(1); } }

Here is the output of jmap command within a few seconds interval:

user@t1007:~> jmap -d64 -histo:live 29201|grep WeakReference 8: 22493 1079664 java.lang.ref.WeakReference 31: 1 32144 [Ljava.lang.ref.WeakReference; 106: 17 952

com.sun.jmx.mbeanserver.WeakIdentityHashMap$IdentityWeakReference user@t1007:~> jmap -d64 -histo:live 29201|grep WeakReference 8: 23191 1113168 java.lang.ref.WeakReference 31: 1 32144 [Ljava.lang.ref.WeakReference; 103: 17 952

com.sun.jmx.mbeanserver.WeakIdentityHashMap$IdentityWeakReference user@t1007:~> jmap -d64 -histo:live 29201|grep WeakReference 8: 23804 1142592 java.lang.ref.WeakReference 31: 1 32144 [Ljava.lang.ref.WeakReference; 103: 17 952 com.sun.jmx.mbeanserver.WeakIdentityHashMap$IdentityWeakReference

Note that jmap command forces FullGC.

JVM settings: export JVM_OPT="\ -d64 \ -Xms200m -Xmx200m \ -XX:MaxNewSize=64m \ -XX:NewSize=64m \ -XX:+UseParNewGC \ -XX:+UseConcMarkSweepGC \ -XX:MaxTenuringThreshold=10 \ -XX:SurvivorRatio=2 \ -XX:CMSInitiatingOccupancyFraction=60 \ -XX:+UseCMSInitiatingOccupancyOnly \ -XX:+CMSParallelRemarkEnabled \ -XX:+DisableExplicitGC \ -XX:+CMSClassUnloadingEnabled \ -XX:+PrintGCTimeStamps \ -XX:+PrintGCDetails \ -XX:+PrintTenuringDistribution \ -XX:+PrintGCApplicationConcurrentTime \ -XX:+PrintGCApplicationStoppedTime \ -XX:+PrintGCApplicationStoppedTime \ -XX:+PrintClassHistogram \ -XX:+ParallelRefProcEnabled \ -XX:SoftRefLRUPolicyMSPerMB=1 \ -verbose:gc \ -Xloggc:$GCLOGFILE"

java version "1.6.0_18" Java(TM) SE Runtime Environment (build 1.6.0_18-b07) Java HotSpot(TM) Server VM (build 16.0-b13, mixed mode)

Solaris 10/Sun Fire(TM) T1000

© Stack Overflow or respective owner

Related posts about memory-leak

Related posts about weakreference