Need help identifying root path

Use this forum to discuss subjects that don't belong in the other forums.
Post Reply

Need help identifying root path

Post by mikeyd » Thu Nov 03, 2005 8:54 pm

I am working on a .NET winforms app and am experiencing a lot of memory leaks. I am having trouble identifying where exactly Im keeping references to certain objects which I believe should be GCd.
A typical example, lets say I have the following code:

void someFunction(){
using (FormEx f = new FormX()){

Now, in form f I tried creating a Dispose() function, I set all member variables to null etc. nothing helps and using Profiler I see that instance f is still reachable but I cant tell exactly how. Here is a list of 'Referenced By' given by the Profiler. It would seem to me that none of these are root references and are actually refereced BY my form. For example the tab control and wingrids are part of the form etc...

Infragistics.Win.UltraWinEditors UltraDateTimeEditor #108,218
Infragistics.Win.UltraWinGrid AfterSelectChangeEventHandler #116,289
Infragistics.Win.UltraWinTabControl SelectedTabChangedEventHandler #116,203
Infragistics.Win.UltraWinTabControl SelectedTabChangedEventHandler #117,961
Infragistics.Win.UltraWinToolbars ToolClickEventHandler #117,974
System.ComponentModel EventHandlerList #110,791
System.Windows.Forms Control.ControlNativeWindow #110,489
System.Windows.Forms VScrollProperties #110,796
System.Windows.Forms HScrollProperties #110,797
System.Windows.Forms Panel #110,802
System.Windows.Forms Form.ControlCollection #117,969
System.Windows.Forms FormClosedEventHandler #118,085
System.Windows.Forms FormClosingEventHandler #118,087
System EventHandler #113,282
System EventHandler #113,286

Any help is appreciated. Thanks,



Post by mikeyd » Thu Nov 03, 2005 10:21 pm

Well I think I solved the problem. If your having similar problems check out this article ... entmessage

Basically an object will not be garbage collected unless bindings are cleared. Doing this manually works.


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

Post by Andreas Suurkuusk » Tue Nov 08, 2005 9:46 pm

It's good that you managed to solve your problem. I just want to comment on your initial question.

The Referenced by list only contains the immediate references to the selected instance. It is very common that this list does not contain any roots. In order to find out why your instance has not been garbage collected, you have to look at the Root paths of the instance. A root path shows the path from a root, through other instances and to the selected instance. It tells you why an instance has not been garbage collected.

In your case you might have had a root path similar to:

System.EventHandler #113,282
SomeClass #xxxx
ArrayList #xxxx
SomeClass _instances

Where _instances is a static field of some class.

If the root paths looks like the one above, it indicates that you have an EventHandler that is not properly removed from an instance that has a longer life-time than the investigated one. To allow the investigated instance to be garbage collected, the EventHandler has to be removed. This might be easy to do (if your code adds the EventHandler), or it might be hard (if code out of your control adds the EventHandler).
Best regards,

Andreas Suurkuusk
SciTech Software AB

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 6 guests