Uploaded image for project: 'SLF4J'
  1. SLF4J
  2. SLF4J-469

Potential memory leaks if there is no underlying implementation

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Critical Critical
    • 2.0.0-alpha2, 1.7.30
    • 1.7.26
    • None
    • java 8 

      slf4j 1.7.26

       

    • normal
    • P2

    Description

       

      If I don't have  'logback'  'log4j'...... Implementation class

      The problem lies in the method 

      public static ILoggerFactory getILoggerFactory()

      first  Thread1:

      if (INITIALIZATION_STATE == UNINITIALIZED) {
      
         init.....
      
      }
      

      secode Thread2:

      case ONGOING_INITIALIZATION:
            return SUBST_FACTORY;

       obtained "SUBST_FACTORY",

       and obtained "SubstituteLogger"

       

      third:

      Thread1: 

      //init failed cache "NoClassDefFoundError"
      INITIALIZATION_STATE = NOP_FALLBACK_INITIALIZATION;
      

      The SubstituteLogger obtained by Thread2 will always output the log to the queue until the memory overflows.

      // code placeholder
      
      synchronized public  Logger getLogger(String name) {
          SubstituteLogger logger = loggers.get(name);
          if (logger == null) {
              logger = new SubstituteLogger(name, eventQueue, postInitialization);
              loggers.put(name, logger);
          }
          return logger;
      }
      
      public void info(String msg) {
          delegate().info(msg);
      }
      
      Logger delegate() {
          if(_delegate != null) {   //_delegate== null forever
              return _delegate;
          }
          if(createdPostInitialization) {  createdPostInitialization == false forever
              return NOPLogger.NOP_LOGGER;
          } else {
              return getEventRecordingLogger();  
          }
      }
      
      

       

       

       

       

      Attachments

        Activity

          People

            ceki Ceki Gülcü
            yellyu yu
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: