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

LogManager Cleaner prevents garbage collection of current context class loader.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • tbd
    • 9
    • core-libs
    • None

      From: Stanimir Simeonoff:

      <<
      On leaks. The c-tor of LogManager leaks the thread group and the current AccessControlContext till JVM shutdown. The constructor code should be something like the one below with Cleaner getting ThreadGroup in its c-tor as well.


          java.security.AccessController.doPrivileged(//zip thread.inheritedAccessControlContext
              new java.security.PrivilegedAction<Void>() {
              public Void run() {
                  // put the cleaner in the systsm threadgroup
                  ThreadGroup grp = Thread.currentThread().getThreadGroup();
                  for(ThreadGroup parent;null!=(parent = grp.getParent());) {
                      grp = parent;
                  }

                  Cleaner cleaner = new Thread(grp);
                  cleaner.setContextClassLoader(null);//zip the classloader
                 
                  // Add a shutdown hook to close the global handlers.
                  try {
                      Runtime.getRuntime().addShutdownHook(cleaner);
                  } catch (IllegalStateException e) {
                      // If the VM is already shutting down,
                      // We do not need to register shutdownHook.
                  }

                  return null;
              }
          });
      >>

      see http://mail.openjdk.java.net/pipermail/core-libs-dev/2014-September/028667.html

            dfuchs Daniel Fuchs
            dfuchs Daniel Fuchs
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: