Menu

#335 AsyncAppender leads to memory leaks

v1.2.0
open
9
2020-05-22
2016-09-15
davy
No

When i use the AsyncAppender in V1.2.0, VS2010 had detected many memory leaks like this:

{2713} normal block at 0x00000000039C3070, 40 bytes long. Data: <@ I > 40 8B 49 00 00 00 00 00 FF FF FF FF 00 00 00 00
{2712} normal block at 0x00000000039BE0B0, 72 bytes long. Data: < @ @ > 08 EE 86 40 01 00 00 00 10 EE 86 40 01 00 00 00
{2711} normal block at 0x00000000039C1F40, 40 bytes long. Data: < I > E0 8A 49 00 00 00 00 00 FF FF FF FF 00 00 00 00
{2710} normal block at 0x00000000039BE000, 64 bytes long. Data: <(z @ 8z @ > 28 7A 87 40 01 00 00 00 38 7A 87 40 01 00 00 00
{2709} normal block at 0x00000000039C1ED0, 8 bytes long. Data: < > E4 01 00 00 00 00 00 00
{2708} normal block at 0x00000000039BDA00, 8 bytes long. Data: < > E0 01 00 00 00 00 00 00
{2707} normal block at 0x00000000039C1E40, 40 bytes long. Data: < I > 80 8A 49 00 00 00 00 00 FF FF FF FF 00 00 00 00
{2706} normal block at 0x00000000039BF370, 16 bytes long. Data: < > 18 A2 9B 03 00 00 00 00 00 00 00 00 00 00 00 00
{2705} normal block at 0x00000000039BF2E0, 40 bytes long. Data: < I > 20 8A 49 00 00 00 00 00 FF FF FF FF 00 00 00 00
{2704} normal block at 0x00000000039BA210, 112 bytes long. Data: < @ p > B8 C4 87 40 01 00 00 00 70 F3 9B 03 00 00 00 00
{2701} normal block at 0x00000000039B9300, 8 bytes long. Data: < > 00 00 00 00 00 00 00 00
{2309} normal block at 0x00000000039C1DC0, 16 bytes long. Data: < > 80 A4 9B 03 00 00 00 00 00 00 00 00 00 00 00 00
{2308} normal block at 0x00000000039C1D30, 40 bytes long. Data: <p=E > 70 3D 45 00 00 00 00 00 FF FF FF FF 00 00 00 00
{2307} normal block at 0x00000000039C1CB0, 16 bytes long. Data: < - @ > 88 2D 87 40 01 00 00 00 01 CD CD CD CD CD CD CD
{2306} normal block at 0x00000000039C0E70, 16 bytes long. Data: < > 18 A4 9B 03 00 00 00 00 00 00 00 00 00 00 00 00
{2305} normal block at 0x00000000039C0DF0, 16 bytes long. Data: < @ @ > 90 8C 87 40 01 00 00 00 40 06 9B 03 00 00 00 00
{2304} normal block at 0x00000000039BA540, 40 bytes long. Data: <P<E > 50 3C 45 00 00 00 00 00 FF FF FF FF 00 00 00 00
{2303} normal block at 0x00000000039BA400, 208 bytes long. Data: < | @ H| @ > 08 7C 87 40 01 00 00 00 48 7C 87 40 01 00 00 00

Discussion

  • Václav Haisman

    Václav Haisman - 2016-09-15
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,3 +1,22 @@
     **When i use the AsyncAppender in V1.2.0, VS2010 had detected many memory leaks like this:**
    
    -{2713} normal block at 0x00000000039C3070, 40 bytes long. Data: <@ I > 40 8B 49 00 00 00 00 00 FF FF FF FF 00 00 00 00 {2712} normal block at 0x00000000039BE0B0, 72 bytes long. Data: < @ @ > 08 EE 86 40 01 00 00 00 10 EE 86 40 01 00 00 00 {2711} normal block at 0x00000000039C1F40, 40 bytes long. Data: < I > E0 8A 49 00 00 00 00 00 FF FF FF FF 00 00 00 00 {2710} normal block at 0x00000000039BE000, 64 bytes long. Data: <(z @ 8z @ > 28 7A 87 40 01 00 00 00 38 7A 87 40 01 00 00 00 {2709} normal block at 0x00000000039C1ED0, 8 bytes long. Data: < > E4 01 00 00 00 00 00 00 {2708} normal block at 0x00000000039BDA00, 8 bytes long. Data: < > E0 01 00 00 00 00 00 00 {2707} normal block at 0x00000000039C1E40, 40 bytes long. Data: < I > 80 8A 49 00 00 00 00 00 FF FF FF FF 00 00 00 00 {2706} normal block at 0x00000000039BF370, 16 bytes long. Data: < > 18 A2 9B 03 00 00 00 00 00 00 00 00 00 00 00 00 {2705} normal block at 0x00000000039BF2E0, 40 bytes long. Data: < I > 20 8A 49 00 00 00 00 00 FF FF FF FF 00 00 00 00 {2704} normal block at 0x00000000039BA210, 112 bytes long. Data: < @ p > B8 C4 87 40 01 00 00 00 70 F3 9B 03 00 00 00 00 {2701} normal block at 0x00000000039B9300, 8 bytes long. Data: < > 00 00 00 00 00 00 00 00 {2309} normal block at 0x00000000039C1DC0, 16 bytes long. Data: < > 80 A4 9B 03 00 00 00 00 00 00 00 00 00 00 00 00 {2308} normal block at 0x00000000039C1D30, 40 bytes long. Data: <p=E > 70 3D 45 00 00 00 00 00 FF FF FF FF 00 00 00 00 {2307} normal block at 0x00000000039C1CB0, 16 bytes long. Data: < - @ > 88 2D 87 40 01 00 00 00 01 CD CD CD CD CD CD CD {2306} normal block at 0x00000000039C0E70, 16 bytes long. Data: < > 18 A4 9B 03 00 00 00 00 00 00 00 00 00 00 00 00 {2305} normal block at 0x00000000039C0DF0, 16 bytes long. Data: < @ @ > 90 8C 87 40 01 00 00 00 40 06 9B 03 00 00 00 00 {2304} normal block at 0x00000000039BA540, 40 bytes long. Data: <P<E > 50 3C 45 00 00 00 00 00 FF FF FF FF 00 00 00 00 {2303} normal block at 0x00000000039BA400, 208 bytes long. Data: < | @ H| @ > 08 7C 87 40 01 00 00 00 48 7C 87 40 01 00 00 00
    +```
    +{2713} normal block at 0x00000000039C3070, 40 bytes long. Data: <@ I > 40 8B 49 00 00 00 00 00 FF FF FF FF 00 00 00 00
    +{2712} normal block at 0x00000000039BE0B0, 72 bytes long. Data: < @ @ > 08 EE 86 40 01 00 00 00 10 EE 86 40 01 00 00 00
    +{2711} normal block at 0x00000000039C1F40, 40 bytes long. Data: < I > E0 8A 49 00 00 00 00 00 FF FF FF FF 00 00 00 00
    +{2710} normal block at 0x00000000039BE000, 64 bytes long. Data: <(z @ 8z @ > 28 7A 87 40 01 00 00 00 38 7A 87 40 01 00 00 00
    +{2709} normal block at 0x00000000039C1ED0, 8 bytes long. Data: < > E4 01 00 00 00 00 00 00
    +{2708} normal block at 0x00000000039BDA00, 8 bytes long. Data: < > E0 01 00 00 00 00 00 00
    +{2707} normal block at 0x00000000039C1E40, 40 bytes long. Data: < I > 80 8A 49 00 00 00 00 00 FF FF FF FF 00 00 00 00
    +{2706} normal block at 0x00000000039BF370, 16 bytes long. Data: < > 18 A2 9B 03 00 00 00 00 00 00 00 00 00 00 00 00
    +{2705} normal block at 0x00000000039BF2E0, 40 bytes long. Data: < I > 20 8A 49 00 00 00 00 00 FF FF FF FF 00 00 00 00
    +{2704} normal block at 0x00000000039BA210, 112 bytes long. Data: < @ p > B8 C4 87 40 01 00 00 00 70 F3 9B 03 00 00 00 00
    +{2701} normal block at 0x00000000039B9300, 8 bytes long. Data: < > 00 00 00 00 00 00 00 00
    +{2309} normal block at 0x00000000039C1DC0, 16 bytes long. Data: < > 80 A4 9B 03 00 00 00 00 00 00 00 00 00 00 00 00
    +{2308} normal block at 0x00000000039C1D30, 40 bytes long. Data: <p=E > 70 3D 45 00 00 00 00 00 FF FF FF FF 00 00 00 00
    +{2307} normal block at 0x00000000039C1CB0, 16 bytes long. Data: < - @ > 88 2D 87 40 01 00 00 00 01 CD CD CD CD CD CD CD
    +{2306} normal block at 0x00000000039C0E70, 16 bytes long. Data: < > 18 A4 9B 03 00 00 00 00 00 00 00 00 00 00 00 00
    +{2305} normal block at 0x00000000039C0DF0, 16 bytes long. Data: < @ @ > 90 8C 87 40 01 00 00 00 40 06 9B 03 00 00 00 00
    +{2304} normal block at 0x00000000039BA540, 40 bytes long. Data: <P<E > 50 3C 45 00 00 00 00 00 FF FF FF FF 00 00 00 00
    +{2303} normal block at 0x00000000039BA400, 208 bytes long. Data: < | @ H| @ > 08 7C 87 40 01 00 00 00 48 7C 87 40 01 00 00 00
    +```
    
     
  • Václav Haisman

    Václav Haisman - 2016-09-15

    Is it possible that this is already fixed by the following change set? 6adafa9d7bc9e56539cba90226dcd8d83955548d

     

    Last edit: Václav Haisman 2016-09-15
    • davy

      davy - 2016-09-15

      this method can reduce the amount of memory leaks, but it also leads to a lot of memory leaks.
      When I did not use "log4cplus.appender.INFO_MSGS=log4cplus::AsyncAppender " in the config file, all of the memory leaks disappear.

       
      • Václav Haisman

        Václav Haisman - 2016-09-15

        When is this leak observed? Is it observed as constant increase in memory consumption over time or is this something you see only when you applicaiton exists? I have had memory leaks reported that were not actual leaks. They were only reported as leaks because the memory leak reporting routine ran before all of the memory could be freed.

         
        • davy

          davy - 2016-09-15

          It occurred when I only initial the async appender.
          It's my config file:
          log4cplus.rootLogger=TRACE, A1
          log4cplus.appender.A1=log4cplus::AsyncAppender
          log4cplus.appender.A1.Appender=log4cplus::RollingFileAppender
          log4cplus.appender.A1.Appender.File=log/debug_info_msgs.log
          log4cplus.appender.A1.Appender.QueueLimit=10000
          log4cplus.appender.A1.Appender.ImmediateFlush=false
          log4cplus.appender.A1.Appender.MaxFileSize=1000MB
          log4cplus.appender.A1.Appender.MaxBackupIndex=5
          log4cplus.appender.A1.Appender.layout=log4cplus::PatternLayout
          log4cplus.appender.A1.Appender.layout.ConversionPattern=%D{[%Y-%m-%d %H:%M:%S.%q]} [%-5p]

          It's the related code:
          LogLog::getLogLog()->setInternalDebugging(false);
          Logger rootLogger = Logger::getRoot();
          PropertyConfigurator::doConfigure(LOG4CPLUS_TEXT("log4cplus.properties"));
          rootLogger.setLogLevel(lv);

          Logger::getRoot().shutdown();
          
          Thank you!
          
           
        • davy

          davy - 2016-09-15

          It occurred when I only initial the async appender. This is my config file:

           log4cplus.rootLogger=TRACE, A1 
           log4cplus.appender.A1=log4cplus::AsyncAppender 
           log4cplus.appender.A1.Appender=log4cplus::RollingFileAppender
           log4cplus.appender.A1.Appender.File=log/debug_info_msgs.log 
           log4cplus.appender.A1.Appender.QueueLimit=10000 
           log4cplus.appender.A1.Appender.ImmediateFlush=false 
           log4cplus.appender.A1.Appender.MaxFileSize=1000MB 
           log4cplus.appender.A1.Appender.MaxBackupIndex=5 
           log4cplus.appender.A1.Appender.layout=log4cplus::PatternLayout 
           log4cplus.appender.A1.Appender.layout.ConversionPattern=%D{[%Y-%m-%d %H:%M:%S.%q]} [%-5p]
          

          This is the related code:

           LogLog::getLogLog()->setInternalDebugging(false);
           Logger rootLogger = Logger::getRoot();
           PropertyConfigurator::doConfigure(LOG4CPLUS_TEXT("log4cplus.properties"));
           rootLogger.setLogLevel(lv);
          
          Logger::getRoot().shutdown();
          

          And when I delete the config line: log4cplus.appender.A1=log4cplus::AsyncAppender

          To config file:

           log4cplus.rootLogger=TRACE, A1 
           log4cplus.appender.A1.Appender=log4cplus::RollingFileAppender
           log4cplus.appender.A1.Appender.File=log/debug_info_msgs.log 
           log4cplus.appender.A1.Appender.QueueLimit=10000 
           log4cplus.appender.A1.Appender.ImmediateFlush=false 
           log4cplus.appender.A1.Appender.MaxFileSize=1000MB 
           log4cplus.appender.A1.Appender.MaxBackupIndex=5 
           log4cplus.appender.A1.Appender.layout=log4cplus::PatternLayout 
           log4cplus.appender.A1.Appender.layout.ConversionPattern=%D{[%Y-%m-%d %H:%M:%S.%q]} [%-5p]
          

          Then, all the memory leaks disappeared

           

          Last edit: Václav Haisman 2016-09-15
          • Václav Haisman

            Václav Haisman - 2016-09-15

            Thank you for the details. However, one question still remains. Is this "leak" detectable during runing time of your application by visible increase in memory consumption over time or is this visible only at application shutdown? As I have mentioned earlier, sometimes these leaks detected by some tools are not actually leaks.

             
            • davy

              davy - 2016-09-15

              this visible only at application shutdown and only when i used async mode.
              but these 'not actually leaks' may conceal some actually leaks in the program and i cannot distinguish them.
              Why async appender's initialization (even not start to log) leads to 'not actually leaks'? I use VS2010's own memory leaks detected tools. Thank you.

               
            • davy

              davy - 2016-09-16

              Should I use log4cplus::threadCleanup() everytimes after I write into a log to avoid memory leaks? I use multi-threaded static library. Thank you

               
  • Václav Haisman

    Václav Haisman - 2016-09-15
    • assigned_to: Václav Haisman
     
  • Václav Haisman

    Václav Haisman - 2017-01-29

    I have fixed a memory leak in AsyncAppender on close that was detectable on Linux. Hopefully, this will also solve issues for Windows.

     
  • Guglielmo Fanini

    I am observing memory leaks in log4cplus version 2.0 compiled as static library with windows visual studio 2015, logging only to a rolling file, not console or other appenders, since I cannot terminate the thread which needs to run continuosly in a server, should I call log4cplus::threadCleanup() periodically or what ?
    This is in a pre existing project I am working on it's not my choice.

     

    Last edit: Guglielmo Fanini 2020-05-22

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.