问题
We've had a long term issue with one of our products consuming GBs of memory when in production. We often get low memory warnings on the server, and finally today I finally had chance to sit down with a memory profiler and see where the memory is going. In development, with the same database and config, the application's private working set is 450MB. On the production server, the amount of memory allocated to that process is 3.7GB.
Using Ants Memory Profiler, I determined that 2.906GB of that memory is being allocated to the Generation 1 Heap:
This amount of memory does get utilised on application start as we load a lot of data from the database to generate some caches. However, it all gets cleaned up, as you can see by the fact all of the data in the graph above is allocated, but not used. Here's the complete overview:
As you can see, the LOH is pretty much empty and not fragmented. I know that the LOH doesn't get compacted, unless you specifically set CompactOnce to the applicable GCSettings enum. But I was under the impression that the Generation 0-2 heaps do get compacted and should get free space released? Or does the CLR just assume that because that much memory was consumed once, that the application should keep addressing that memory in case it needs that much again?
To me, our app should only be consuming about 600-700MB (most of which is the CLR). So:
- Does anyone know why this free space is remaining allocated and only on a production server and not on development laptops?
- Is there any way to manually release this free memory from the gen 1 heap?
来源:https://stackoverflow.com/questions/34659229/generation-1-heap-consuming-gigs-of-memory-as-free-space