Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6942989

Memory leak of java.lang.ref.WeakReference objects

XMLWordPrintable

    • b102
    • generic, x86
    • generic, linux, solaris_10, windows_xp
    • Not verified

        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.

        More on http://forums.java.net/jive/thread.jspa?threadID=75651&tstart=0
        The forum thread has an additional posting that clarifies the APIs
        used by the real application:


        Just more information about the issue.
        The code above is just an artificial piece of code which easily reproduces the problem.
        In the live system the allocation call tree looks like:
        ...
        com.sun.jmx.mbeanserver.JmxMBeanServer.getAttribute(ObjectName name, String attribute)
        ...
        com.sun.jmx.trace.TraceManager.getLogger(int type)
        java.util.logging.Logger.getLogger(String name)

        In 6 days the number of WeakReference instances grows up to 240 000 (11 Mb). So the increase is 2 Mb per day.

        The issue is reproduced on Linux and Solaris.
        Linux version:
        Red Hat Enterprise Linux Server release 5.3 (Tikanga)
        Linux rhone 2.6.18-128.1.14.el5 #1 SMP Mon Jun 1 15:52:58 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux

        Solaris version:
        Solaris 10 11/06 s10s_u3wos_10 SPARC
        Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
        Use is subject to license terms.
        Assembled 14 November 2006

              dcubed Daniel Daugherty
              ahurvitz Amit Hurvitz (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: