I wrote a long TCP connection socket server in C#. Spike in memory in my server happens. I used dotNet Memory Profiler(a tool) to detect where the memory leaks. Memory Profiler indicates the private heap is huge, and the memory is something like below(the number is not real,what I want to show is the GC0 and GC2's Holes are very very huge, the data size is normal):
Managed heaps - 1,500,000KB
Normal heap - 1400,000KB
Generation #0 - 600,000KB
Data - 100,000KB
"Holes" - 500,000KB
Generation #1 - xxKB
Data - 0KB
"Holes" - xKB
Generation #2 - xxxxxxxxxxxxxKB
Data - 100,000KB
"Holes" - 700,000KB
Large heap - 131072KB
Large heap - 83KB
Overhead/unused - 130989KB
Overhead - 0KB
Howerver, what is GC hole? dotNet Memory Profiler's documention definite the "Holes":
“Holes” represent memory that is unused between two allocated instances. “Holes” appear when the heap is not fully compacted, due to pinned instances or optimizations in the garbage collector.
What I want to know is:
- "holes" appear between what kind of two allocated instances?
- what kind of instances are pinned?
- How to compact the heap?
I hope somebody can explain it.