Reputation: 10167
I have an ASP.NET MVC web application that's running in its own app pool (.NET 4.7.1 app, 64bit, IIS 10) on a server (Windows Server 2016) with lots of free RAM. Just after I start the application and load a first web page, I look at the task manager, and see the w3wp.exe process using quite a lot of memory:
I think it's a bit too much considering it's just one web app. So I launch dotMemory and attach to the process. I get those results:
Here, it says the total used is 1.1 GB (not just 853 MB), from which unmanaged memory is 429.5 MB, the rest is the heap.
When I get a snapshot of that (as shown in the screenshot), it says 1.08 GB total, out of which .NET is 75.06 MB (rest is unmanaged). Those numbers don't seem to add up. One says 429.5 unmanaged memory, the other shows like 1 GB of unmanaged memory. Does it mean that the heaps are counted as unmanaged memory in the snapshot?
All the dotMemory lets me peek in are the 63.73 MB of .NET used memory, where I can see how many objects of which types I have.
I'm curious to understand what's the rest of that. What's in the other gigabyte of memory I cannot peek in? Is it stuff that GC hasn't released yet? If yes, why doesn't running "Force GC" in dotMemory decrease it significantly?
Also, where does all the unmanaged memory come from? All I could find online was that unmanaged memory leaks usually happen if some bitmaps or P/Invoke stuff isn't released correctly. But my app pool has this usage from the start (so it's not leaks accumulated over time), and it's neither dealing with bitmaps or images nor calling native DLLs or using third-party libraries that do. The other option might be that it's ASP.NET cache, but it's only used very little, and I don't think that it would have 400 MB in it just after a single page load.
I've observed in the past that IIS app pools can be quite greedy if they've got a lot of free memory available, but this seems quite excessive - 1 GB vs 60 MB. I don't understand what's going on there.
I don't think there are memory leaks, as I can keep the app pool running for weeks, and the memory doesn't increase significantly. It's just that it uses quite a lot of memory when I think it shouldn't use that much.
Can you please help me find some resources to study or tools to help me investigate the issue?
Upvotes: 7
Views: 3339
Reputation: 2508
Gen 0 heap size displays the maximum bytes that can be allocated in generation 0; it does not indicate the current number of bytes allocated in generation 0. http://msdn.microsoft.com/en-us/library/x2tyfybc(v=vs.110).aspx
Look at this answer for more details. TL;DR - ASP creates huge heap for generation 0 for some reason.
https://stackoverflow.com/a/26955929/779822
Upvotes: 1