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

Using MXBeans can lead to memory leaks

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 6
    • Fix Version/s: 6u1
    • Component/s: core-svc
    • Labels:
    • Subcomponent:
    • Introduced In Version:
      6
    • Resolved In Build:
      b01
    • CPU:
      generic
    • OS:
      generic

      Backports

        Description

        I ran a simple test that creates a ClassLoader, executes some MXBean code using the ClassLoader, then waits for the ClassLoader to be garbage-collected. The ClassLoader is *not* garbage-collected, because of two problems:

        (1) The class com.sun.jmx.mbeanserver.MXBeanLookup keeps a WeakHashMap<MBeanServerConnection, MXBeanLookup> in order to find the lookup table for a given MBeanServerConnection. Since MXBeanLookup has a reference to its MBeanServerConnection, entries in this WeakHashMap never go away. This means that if you create a number of connections to remote MBeanServers over the lifetime of an application, and you use those connections to navigate MXBean references, then you will build up entries in the WeakHashMap.

        (2) The class javax.management.MBeanServerInvocationHandler keeps a WeakHashMap<Class<?>, MXBeanProxy> in order to avoid having to reapply the introspection logic on an MXBean interface every time that interface is used to make a proxy. Since MXBeanProxy has a field Map<Method, Handler> and the Methods in question come from the Class<?> that is a key in the WeakHashMap, again we have the classic bug where the values in a WeakHashMap strongly-reference the keys. This means that if you run some code from a ClassLoader that creates proxies using interfaces defined by that ClassLoader, then the ClassLoader will never be gc'd.

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  emcmanus Eamonn McManus
                  Reporter:
                  emcmanus Eamonn McManus
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  0 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: