Page 1 of 1

Investigating a memory leak with .NET Memory Profiler 4.6

Posted: Tue Jan 20, 2015 9:39 am
by S.Tendick

I am trying to investigate a memory leak in a quite complex application. I have used about 10 different profiling tools and .NET Memory Profiler seems to fit best.

I started the guided profiling "Investigate memory leaks", performed the operation that I consider to be the memory leak and took a snapshot. Then I performed the operation again and took another snapshot.

I found the form "FrmCvBlobInspection" which I think is the problem. I just don't really know how to go on from here. I displayed the type details of this form but the instances graph is really big and overwhelming, even if I highlight and align the root path. Could you please provide me with some help to solve those memory leaks?

Thank you in advance for any advice.

Best Regards

Simon Tendick

edit: The upload of my session file does not seem to have worked, therefore I provide you with the session file at

Re: Investigating a memory leak with .NET Memory Profiler 4.

Posted: Tue Jan 20, 2015 2:48 pm
by Andreas Suurkuusk
In the session file I can see that you have several form instances that are disposed but not yet garbage collected, e.g. FrmCalcResults.
Analysis issues
A disposed form should normally be garbage collected soon after being disposed, so I started to investigate one of these instances, a new FrmCalcResults instance (#134,226).
The instance is a "Disposed instance with indirect EventHandler roots", which can be seen in the instance graph. The instance graph shows two ToolStrip instances that are rooted by EventHandlers (and as can be seen in the first screenshot, there are ToolStrip instances that are directly rooted by EventHandlers). The event handlers are added and removed based on the Visible property and removed when being disposed. However, the ToolStrip instances are never disposed, even though I believe they should be.

The ToolStrip instances are created in the method SysconaDisplay.InitializeComponent. If the SysconaDisplay instance is properly disposed, then the ToolStrip instances will also be disposed. Since you have SysconaDisplay instances that are kept alive by only EventHandlers, I assume that the instances are no longer in use. I recommend that you make sure that the SysconaDisplay instances, and other form instances, are properly disposed. This will hopefully make sure that you no longer have a memory leak.

As I mentioned above, the ToolStrip event handlers are updated when the Visible property is updated, but this VisibleChanged event is always not reliably invoked. You can read more about it in this article.

Re: Investigating a memory leak with .NET Memory Profiler 4.

Posted: Wed Jan 21, 2015 9:06 am
by S.Tendick
Hello Mr. Suurkuusk,

with your help and the help of your tool I actually did find our memory leak and was able to close it. Thank you very much for this great tool and even more for your effort!

Best regards