Understanding memory leaks in ASP.net using RedGate Memory Profiler
Asked Answered
T

1

6

I am running a large ASP.net 4.0 website. It uses a popular .Net content management system, has thousands of content items, hundreds of concurrent users - is basically a heavy website.

Over the course of 1 day the memory usage of the IIS7 worker process can rise to 8-10GB. The server has 16GB installed and is currently set to recycle the app pool once per day.

I am getting pressured to reduce memory usage. Much of the memory usage is due to caching of large strings of data - but the cache interval is only set to 5-10 minutes - so these strings should eventually expire from memory.

However after running RedGate Memory Profiler I can see what I think are memory leaks. I have filtered my Instance List results by objects that are "kept in memory exclusively by Disposed Objects" ( I read on the RedGate forum that this is how you find memory leaks ). This gave me a long list of strings that are being held in memory.

For each string I use Instance Retention Graph to see what holds it in memory. The System.string objects seem to have been cached at some point by System.Web.Caching.CacheDependency. If I follow the graph all the way up it goes through various other classes including System.Collections.Specialized.ListDictionary until it reaches System.Web.FileMonitor. This makes some sense as the strings are paths to a file (images / PDFs / etc).

It seems that the CMS is caching paths to files, but these cached objects are then "leaked". Over time this builds up and eats up RAM.

Sorry this is long winded... Is there a way for me to stop these memory leaks? Or to clear them down without resorting to recycling the app pool? Can I find what class / code is doing the caching to see if I can fix the leak?

Torques answered 20/2, 2013 at 11:18 Comment(0)
O
0

It sounds like the very common problem of stuff being left in memory as part of session state. If that's the case your only options are 1. don't put so much stuff in each user's session, 2. Set the session lifetime to something shorter (the default is 20 minutes, I think), and 3. periodically recycle the app pool.

As part of 1. I found that there are "good ways" and "bad ways" of presenting data in a data grid control. You may want to check that you are copying only the data you need and not accidentally maintaining references to the entire datagrid.

Officer answered 20/2, 2013 at 12:8 Comment(2)
We are already recycling the App Pool but the client sees this as a work around rather than a solution. They are saying, with justification, that the application should not use so much memory.Torques
System.Web.Caching.CacheDependency is rather a use of ASP.NET Caching than a cache in session. This cache is somehow static and shared for all users except if the cache keys are user-specific (not recommended at all and may cause these kinds of issues). Recycling the pool or lowering the session timeout only limit the lifetime of the webapp, not the memory usage.Iodous

© 2022 - 2024 — McMap. All rights reserved.