Investigating a memory leak with .NET Memory Profiler 4.6

Use this forum for questions on how to use .NET Memory Profiler and how to analyse memory usage.
Post Reply
S.Tendick
Posts: 2
Joined: Tue Jan 20, 2015 9:23 am

Investigating a memory leak with .NET Memory Profiler 4.6

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

Hello,

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
http://1drv.ms/1809p2U

Andreas Suurkuusk
Posts: 1005
Joined: Wed Mar 02, 2005 7:53 pm

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

Post by Andreas Suurkuusk » Tue Jan 20, 2015 2:48 pm

In the session file I can see that you have several form instances that are disposed but not yet garbage collected, e.g. FrmCalcResults.
Syscona.png
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).
FrmCalcResults.png
FrmCalcResults
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.
Best regards,

Andreas Suurkuusk
SciTech Software AB

S.Tendick
Posts: 2
Joined: Tue Jan 20, 2015 9:23 am

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

Post by S.Tendick » Wed Jan 21, 2015 9:06 am

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

Simon

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests