0

We have an application we have created using C#, RestSharp, Log4net and Quartz. The Quartz is running tasks every X amount of minutes (about five total tasks) that perform various functions but most of which is working with Active Directory and using RestSharp to communicate with an external service. What we have found is the memory of this service keeps growing until the service is restarted.

We are having a difficult time discovering where the memory leak is. We have gone through the entire code making sure everything was disposed of that has a dispose method, we have nulled StringBuilder objects and arrays we create within the Quartz tasks even though it shouldn't be necessary.

We have taken on the task of creating a process dump when the application is over 500MB (the process starts at 10MB). Examining with Windbg (which isn't my strong suite) we see this:

************************************************************************************************************************
                                              NT HEAP STATS BELOW
************************************************************************************************************************
LFH Key                   : 0x75c77a1078572532
Termination on corruption : ENABLED
          Heap     Flags   Reserv  Commit  Virt   Free  List   UCR  Virt  Lock  Fast 
                            (k)     (k)    (k)     (k) length      blocks cont. heap 
-------------------------------------------------------------------------------------
00000265d7670000 00000002   32604  21192  32552    720   298     6    1      3   LFH
00000265d74a0000 00008000      64      4     64      2     1     1    0      0      
00000265d7640000 00001002     112     64     60      6     5     1    0      0   LFH
00000265d7960000 00001002    1132     88   1080     19     6     2    0      0   LFH
00000265d7ca0000 00001002      60     16     60      4     2     1    0      0      
00000265d7dd0000 00041002      60      8     60      5     1     1    0      0      
00000265f0680000 00041002      60      8     60      4     2     1    0      0      
00000265f0d40000 00001002  533472 518492 533420   2810   712    37    0      0   LFH
-------------------------------------------------------------------------------------

Now from what we can tell is heap 00000265f0d40000 is taking all the memory. When I view this in dotMemory it shows only around 2-3MB of memory being used. My theory this is not .NET memory that is taking this up. We are not using PINVOKE or anything like that but maybe it could be the third party libraries we are using?

I am not really sure where to go from here since I find a lot of topics on looking at .NET memory and not native memory leaks:

0:026> !address 265f0d40000

Usage:                  Heap
Base Address:           00000265`f0d40000
End Address:            00000265`f0d4f000
Region Size:            00000000`0000f000 (  60.000 kB)
State:                  00001000          MEM_COMMIT
Protect:                00000004          PAGE_READWRITE
Type:                   00020000          MEM_PRIVATE
Allocation Base:        00000265`f0d40000
Allocation Protect:     00000004          PAGE_READWRITE
More info:              heap owning the address: !heap 0x265f0d40000
More info:              heap segment
More info:              heap entry containing the address: !heap -x 0x265f0d40000
0:026> !heap -x 0x265f0d40000
Entry             User              Heap              Segment               Size  PrevSize  Unused    Flags
-------------------------------------------------------------------------------------------------------------
00000265f0d40000  00000265f0d40010  00000265f0d40000  00000265f0d40000       720         0         1  busy 
0:026> !heap -stat -h 265f0d40000
 heap @ 00000265f0d40000
group-by: TOTSIZE max-display: 20
    size     #blocks     total     ( %) (percent of total busy bytes)
    370 3cece - d16e420  (44.25)
    33b 6eb0 - 1659290  (4.72)
    50 3cee6 - 130a7e0  (4.02)
    359 452e - e796fe  (3.06)
    fd7 dd6 - db28ba  (2.89)
    318 4530 - d60c80  (2.83)
    336 3758 - b1b490  (2.35)
    42f 2982 - ada6de  (2.29)
    451 1bd3 - 7819c3  (1.59)
    411 1bc3 - 70e3f3  (1.49)
    3de 1bac - 6b0328  (1.41)
    354 1bac - 5c1870  (1.22)
    331 1bac - 584fec  (1.17)
    566 dd6 - 4ab144  (0.99)
    4bd dd6 - 418efe  (0.87)
    491 dde - 3f52be  (0.84)
    484 dd6 - 3e7a58  (0.82)
    47a dd6 - 3deffc  (0.82)
    477 dd6 - 3dc67a  (0.82)
    46a dd6 - 3d129c  (0.81)

After running !heap -flt s 370 it will just print a ton of these:

0000026592e10470 0038 0038  [00]   0000026592e10480    00370 - (busy)
          unknown!printable
        0000026592e107f0 0038 0038  [00]   0000026592e10800    00370 - (busy)
          unknown!printable
        0000026592e10b70 0038 0038  [00]   0000026592e10b80    00370 - (busy)
          unknown!printable
        0000026592e10ef0 0038 0038  [00]   0000026592e10f00    00370 - (busy)
          unknown!printable
        0000026592e11270 0038 0038  [00]   0000026592e11280    00370 - (busy)
          unknown!printable
        0000026592e115f0 0038 0038  [00]   0000026592e11600    00370 - (busy)
          unknown!printable
        0000026592e11970 0038 0038  [00]   0000026592e11980    00370 - (busy)
          unknown!printable
        0000026592e11cf0 0038 0038  [00]   0000026592e11d00    00370 - (busy)
          unknown!printable
        0000026592e12070 0038 0038  [00]   0000026592e12080    00370 - (free)
        0000026592e123f0 0038 0038  [00]   0000026592e12400    00370 - (busy)
          unknown!printable
        0000026592e12770 0038 0038  [00]   0000026592e12780    00370 - (free)
        0000026592e12af0 0038 0038  [00]   0000026592e12b00    00370 - (free)

I would appreciate any assistance because I am at a loss. The memory will continue to grow to well over 1-2GB if we let it.

Jacob
  • 1
  • try use Windbg with SOS: https://stackoverflow.com/questions/2957105/how-can-you-explore-the-managed-heap-in-a-net-application-to-identify-possible – Matt Dec 18 '21 at 01:41
  • I did do this with ".loadby sos clr". Results above included that but didnt post it. The heap with all the memory just prints "unknown!printable" and I don't know how to examine further – Jacob Dec 19 '21 at 02:24
  • What I have found is running the app as a console app does not seem to have any memory leaks. It is only when it is ran as a service in Windows which is weird. Still unable to trace it down. – Jacob Jan 03 '22 at 15:07

0 Answers0