IIS Application Pool taking too much memory

application-poolsasp.netiismemory leakmemory usage

We have IIS running on two servers (IIS8 and 10), and encounter very high memory usage of our ASP.NET WebForms Applications lately, mostly accessed through aspx pages.

What happens is that over time, our application pools consume more and more memory, until the physical memory on the server (64GB) is nearly exhausted. This is definitely not normal.

We tried to find out why this happens but are out of ideas. It is unclear weather this is a memory leak in our application, or normal behaviour, so perhaps someone can shed some light on it.

Facts:

  • Over time, the application pools reserve AND use more and more memory, that is not freed (task manager says that both working set and commit size are very high, so it is actually used/held, right?)

  • memory profilers like ANTS, .dotMemory, .NET MemoryProfiler say that the managed memory consumption is rather low, say 20-200MB, and showing a lot of unmanaged memory, that would be used, but free.

  • they don't give any hint to what might be causing the unmanaged usage, even with snapshots and detailed profiling methods.

  • if we "hammer" the start page with F5 key while not releasing it, we can shoot memory usage up to 2-5 gigabyte in one minute. This is a little insane.

  • we know that IIS/Application pools tend to reserve memory in a opportunistic way the more memory that is available, but this is way too much.

  • the only thing we see is that the front page seems to be held in memory with it's controls and ComponentModel objects, but there is no single reference to any of our page objects or own namespace classes anywhere in the memory profilers.

  • the memory consumption was anecdotally fine a year ago, and stopped at 2-3 gigabytes total , but we can't reproduce it anymore with an old version of the application.

  • it happens on a fresh local installation of IIS under WIN10, too.

  • the applications is built in release mode, optimised, compiled into a single DLL at the moment, also tried without, trace flag on, 5mb in size

It seems that we need to take the application apart, split it into several modules and see how those behave. The assemblies/libraries loaded at runtime can, but shouldn't be the problem.
We actually dont reference that much (FreeTextBox, Microsoft ReportViewer, SharpCompress, Crystal Reports, AjaxControlToolKit 15), we removed all but CrystalReports/AjaxControlToolKit already to see what happens but didn't change.

We also use lots of the WebForms controls, including Timers and UpdatePanels sometimes.

We also don't know how to find the culprit using memoryprofilers, assuming there is a hidden reference causing one or more aspx pages to be held in memory because the .NET class instances never show any link to anything.

We'd be happy to get ANY hint what we might misunderstand regarding memory reservation or how to troubleshoot this memory consumption issue.

Thank you very much for your time!

EDIT (forgot to mention):
– We added GC.Collect/WaitForPendingFinalizers/GC.Collect to our Page_Load function of the start page to see if it helps, and it indeed helps for a while or a bit, until there is a another pressure situation (with F5) where the memory usage just goes up again in an extreme way.

Best Answer

When GC.WaitForPendingFinalizers helps, it could be a sign of memory used by threads. If you start a new seperate thread on page_load, it could use a lot of memory. Start diagnosing the problem by checking count of threads in task manager.