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

LogManager still causes a memory leak

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 7
    • core-libs

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      The java.util.LogManager was reported to hold strong references to logger instances and hence is a potential memory leak. Now this was fixed by replacing the strong with weak references in a normal hashtable (I refer to the evaluation of Bug 4811930). The problem with this fix is that stale entries are never removed. Only when a logger is accessed per name the hasmap entry is potentially removed (given the weak reference is stale). Simply fetching loggers with changing names leads to an out of memory error.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The LogManager has to expunge stale entries systemacially and the memory usage should not increase when no references to the fetched loggers are held.
      ACTUAL -
      Memory consumption steadily increases leading to an out of memory.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread main.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class TestLogManager
      {
      public static void main(String[] args)
      {
      long i=0;
      while(true)
      {
      Logger.getLogger("logger_"+(i++));
      if(i%10000==0)
      {
      System.out.println("Mem: "+(Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory()));
      }
      }
      }
      }
      ---------- END SOURCE ----------

            dcubed Daniel Daugherty
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: