New to This, Trying to Track Down Issue

Use this forum for questions on how to use .NET Memory Profiler and how to analyse memory usage.
Post Reply
FuzzyBoots
Posts: 3
Joined: Wed Nov 09, 2011 1:44 pm

New to This, Trying to Track Down Issue

Post by FuzzyBoots » Wed Nov 09, 2011 1:56 pm

So, I have a fairly complex C# application which I've inherited from another developer. There was previously a known issue where reloading a data file repeatedly led to memory consumption due to old copies of the form not being disposed of. We fixed it by removing some event handlers, but the problem came back. I fixed part of it with the help of Memprofiler (it was actually an interesting side case where a control had a static event that never got released and therefore the controls always had a reference and never got connected even though the only thing which pointed to a given control was itself). Unfortunately, the issue still stands and I'm not following how to follow the indications. I have a screenshot of one of the code paths of the offending application below. Pardon the crude redaction, but I figure I'm best off not broadcasting my company name.
Memory Screenshot.png
Memory Screenshot.png (47.61 KiB) Viewed 7234 times
I can't find an EventHandler belonging to MdiPTU that refers to the form, and I have no idea why there's this Object array. Could anyone give me a hand?

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

Re: New to This, Trying to Track Down Issue

Post by Andreas Suurkuusk » Thu Nov 10, 2011 7:32 am

To get information about why the EventHandler has been added for your FormOpenWatch instance (#19,491) you can take a look at the allocation call stack of the EventHandler. You can get the call stack information by hovering with the mouse over the EventHandler instance (#21,347) in the instance graph. When you know why the EventHandler was added you should hopefully be able to determine how the EventHandler can be removed (e.g. by removing it somehow in the Dispose method of FormOpenWatch).

The Object[] array that is referencing the EventHandler is part of the EventHandler implementation for a multicast EventHandler. When you are investigating EventHandler you often see root paths like:

EventHandler (this is specific EventHandler that is created for the Target you are investigating, in you case #19,491)
Object[] (An array of all EventHandlers added to a multicase EventHandler)
EventHandler (the "root" event handler that is used by the event source to raise the event)
Best regards,

Andreas Suurkuusk
SciTech Software AB

FuzzyBoots
Posts: 3
Joined: Wed Nov 09, 2011 1:44 pm

Re: New to This, Trying to Track Down Issue

Post by FuzzyBoots » Fri Nov 11, 2011 9:09 pm

Ah, and I think I found it. The catch is that I made probably a dozen changes before finding out that there was a section of code where an exception occurred, but was quietly vanished, preventing some of my earlier fixed from running. Therefore, I don't know exactly was the fix. As it is, I aggressively detached events and set values to null upon disposal, and explicitly called Dispose on various methods where I knew an item should be out of scope.

Thank you for your help.

FuzzyBoots
Posts: 3
Joined: Wed Nov 09, 2011 1:44 pm

Re: New to This, Trying to Track Down Issue

Post by FuzzyBoots » Wed Nov 16, 2011 1:48 pm

And it's back again. I found that there was an error in some code where I put a "using" block around a creation of a Graphics object. Removing it let me use the program again, but also seems to result in the memory leak in all of the places that I fixed it before. Very frustrating. Will post later with more details.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 26 guests