views:

203

answers:

3

I have a large .NET C# application with a memory leak. Using ants memory profiler, I can see that there are multiple versions of same user controls in memory and the garbage collector is not collecting them. There is output caching on the web forms but no output caching on the actual user controls.

Is there a reason why the user controls are not being disposed?

How can I identify why and what is keeping them from being disposed of by garbage collector?

+1  A: 

There are a lot of reasons why a user control isn't garbage collected. Look at the code itself, are you instantiating objects (such as record sets) which implement IDisposable that you aren't actually disposing of?

Chris Lively
A: 

If you have output caching enabled on your pages, all child controls will cache as well. As far as multiple instances of your control lingering in memory, give this page a read with some strategies using partial page caching that will help you save on memory.

http://msdn.microsoft.com/en-us/library/k4he1ds5(VS.71).aspx

Wayne Hartman
A: 

Basically an object will not get collected if someone holds at least one reference to it. Look and find who's holding the reference. ANTS Profiler or .NET Memory Profiler (SciTech) will give good insight.

Andrei Rinea