I have a memory leak problem with my .NET 3.5 multi-threaded application run on Window server 2008. I found the process consumed 1 GB memory after few days running and still increasing. This is what I've tried to address the issue :
- The Gen2 Heap Size is increasing non-stop over time while Gen0&Gen1 stay remain.
- The large object heap size stay stable in about 1 MB, which are some objects that I have allocated for life-time of the application (those objects are a few dictionary with specified capacity)
- !EEHeap shown that the app allocate more and more memory segment in Gen2 :
Total LoaderHeap size: 0x79000(495616)bytes
=======================================
Number of GC Heaps: 1
generation 0 starts at 0x1a3bddd0
generation 1 starts at 0x1a375490
generation 2 starts at 0x025a1000
ephemeral segment allocation context: none
segment begin allocated size
025a0000 025a1000 0359f9bc 0x00ffe9bc(16771516)
0bd80000 0bd81000 0c87a5b0 0x00af95b0(11507120)
0dba0000 0dba1000 0e56a2f0 0x009c92f0(10261232)
0f190000 0f191000 0fc9cfd0 0x00b0bfd0(11583440)
10190000 10191000 10998720 0x00807720(8419104)
11190000 11191000 11c380d0 0x00aa70d0(11170000)
12190000 12191000 1295bbf4 0x007cabf4(8170484)
13190000 13191000 13d0e578 0x00b7d578(12047736)
15190000 15191000 158d9534 0x00748534(7636276)
16190000 16191000 16d04c64 0x00b73c64(12008548)
14190000 14191000 14d46794 0x00bb5794(12277652)
17190000 17191000 17d06198 0x00b75198(12013976)
18d60000 18d61000 19942f84 0x00be1f84(12459908)
19d60000 19d61000 1a7dd73c 0x00a7c73c(10995516)
Large object heap starts at 0x035a1000
segment begin allocated size
035a0000 035a1000 036c1aa8 0x00120aa8(1182376)
Total Size 0x97297b4(158504884)
------------------------------
GC Heap Size 0x97297b4(158504884)
- !dumpheap -stat shown that a lot of Free object is increasing over time but the application somehow does not reuse these free memory and allocate more memory overtime:
7207da1c 6825 682500 System.Net.Sockets.OverlappedAsyncResult
70ec88c0 92655 4471548 System.String
70ecb330 12959 10870420 System.Byte[]
004aefc0 17221 133162956 Free
- I have tried to do a GC.Collect() to force an immediate garbage collection of all generation but these huge Free object still stay there.
- Look at these free object with dumpheap -Type Free . The size of these free object is various but i found a lot of contiguous large size which can be reusable :
11af63f4 004aefc0 179468 Free
11b221f4 004aefc0 57212 Free
11b30284 004aefc0 55508 Free
11b3e030 004aefc0 40144 Free
11b47e14 004aefc0 33512 Free
11b505d0 004aefc0 260464 Free
11b9001c 004aefc0 67484 Free
11ba0bf8 004aefc0 619492 Free
12191000 004aefc0 598516 Free
122232f8 004aefc0 166308 Free
1224c0dc 004aefc0 172144 Free
12276240 004aefc0 288408 Free
122bcd18 004aefc0 212100 Free
122f0a78 004aefc0 84348 Free
12305834 004aefc0 70120 Free
12316ef0 004aefc0 112980 Free
12332c84 004aefc0 413500 Free
12398044 004aefc0 192380 Free
123c70ac 004aefc0 62256 Free
123d64f0 004aefc0 62172 Free
123e58e0 004aefc0 109028 Free
12400798 004aefc0 79084 Free
12414108 004aefc0 100440 Free
...
- As I might think the software need to allocate some larger object that does not fit those free memory. So i do a !dumpheap -Type String/System.Byte[] -min 50000 to find large allocated object but i found no one.
Why does .NET not compact/reuse these Free object and how to fix this memory leak issue? Thank you all a lot!