Tutorial :why are user controls not collected by Gargabe Collector?


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?


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.


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?


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.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »