I have an ASP.NET/C# web application that uses a lot of memory.
ANTI Memory Profiler and PerfMon show that my Gen 0 heap is growing rapidly to around 1 GB during Application_Start. I read here that the PerfMon counter for the Gen 0 heap actually shows the "budget" for Gen 0, and not the size (which I accept to mean not all that memory is part of a private workflow?). However, the ANTS profiler shows about 700 MB of “unused memory allocated for .NET,” and this seems to be part of a private workflow (as specified in taskmgr). I assume that this large amount of unused memory is associated with a large heap of Gen 0.
What happens in Application_Start when this happens is that in the while loop I read about a million rows from SqlDataReader. They are used to populate a large cache for later use. Given this, the obvious culprit of a large amount of unused memory was the large fragmentation of the heap of objects, but I do not think so, since I pre-allocate more than is necessary for my large cache object. To be sure, I even tried to comment on the part of the loop that actually adds to my cache object; it had no significance in the amount of allocated unused memory.
As a test, I often tried to force garbage collection of generator 0 during the cycle (against all the recommendations, I know), and this led to the gen0 heap size remaining below 128 MB, and also led to only a few MB of unused free memory. But he also exceeded my processor and forced Application_Start to go too long.
My questions:
1) What could cause the reported Gen 0 heap size to be so large?
2) Is this a problem? In particular, could this be the reason for placing a large amount of unused space for .NET?
3) If so, what should I do to fix this? If I cannot stop the process from using so much memory during Application_Start, I would like to at least make it drop memory when the application shuts down.
source share