I have a 'service' (owin/webapi + odp.net managed) that runs with the 'server gc mode' on x64 machine. After executing test suite memory usage was around 2Gb. I 'generated' memory pressure on that machine (another program that consumed all available memory and more). I was expecting that windows will force .net to release some memory. However it did not. Here is an output from windbg:
0:018> !dumpheap -stat
0:018> !heapstat
Heap Gen0 Gen1 Gen2 LOH
Heap0 455256040 24 24 3713672
Heap1 464550872 24 4327776 727456
Heap2 428541352 10344768 12616 24
Heap3 474250128 24 21350456 24
Total 1822598392 10344840 25690872 4441176
Free space:
Percentage
Heap0 446429064 0 0 1819552SOH: 98% LOH: 48%
Heap1 459823968 0 144 152SOH: 98% LOH:
0%
Heap2 428520936 34904 24 24SOH: 97% LOH:100%
Heap3 474044952 0 336 24SOH: 95% LOH:100%
Total 1808818920 34904 504 1819752
So, there is only around 48Mb really used and 1.8Gb free, most of memory is not in LOH but in Gen 0 heap, but .net would not give that memory back. And meanwhile system was starving for memory.
Service is reading big results from oracle. 10 columns and 800K rows. So that much memory is actually used when reading response of a db (there is extremely inefficient implementation to store results). After response is sent gc is triggered and reclaims memory. As service works in the 'server' mode according to official documentation then size of 'ephemeral segment' is 2Gb for the server service is running. So I suppose .net would not give a part of that segment to OS. Does it sound anything like true?