Confused as to why an object is reported as leaked...

Code and memory profiling for .NET developers.

Moderators: Brian Donahue, richardjm, StephenC

Confused as to why an object is reported as leaked...

Postby tribbles » Fri Feb 13, 2009 1:18 am

I just can't figure out what is holding onto the reference... I run the garbage collector and look at the objects left and this simpel dialog editor is in the list... I look at what references it and I see a couple 'EventHandler ID 633610' and HScrollProperties ID 629023' and such, both I am unable to trace those back to anything in my code...

Going thru my code, I only reference the form once in the code segement below. I have verified that code execution runs all of this code and that the Dispose method is called on the form. I can find no other references to this form and can not fathom how in blue blazes can this be reported as a leak.


using (GaugeIndicatorEditorForm form = new GaugeIndicatorEditorForm(copy)) {

if (form.ShowDialog() == DialogResult.OK) {
gauge.GaugeContainer = GaugeContainer;

EditorUtil.HostComponentChanged(context, gauge.GaugeContainer);

if (preview != null) {
preview.DundasRenderDundas(gauge.GaugeContainer, false);
}
}
}


Cut and paste doesn't work for code apparently, so I had to clean it up by hand, hopefully I didn't delete an paren or semi colon by accident. Either way, with code this fricken simple, I just can't figure out why it is being reported as a leak... The parent class of this code is a UITypeEditor and it gets called from the MS property grid.
tribbles
 
Posts: 2
Joined: Fri Feb 13, 2009 1:08 am
Location: USA

Postby Brian Donahue » Fri Feb 13, 2009 6:22 pm

Hi,

It sounds like the infamous "event handler" gotcha in .NET. If you hook an event handler to an object, you must remember to dereference it when no longer needed. There could also be unintended references created inside the event handler as in the ASP .NET DataGrid example pointed out here.
Brian Donahue
 
Posts: 6670
Joined: Mon Aug 23, 2004 10:48 am

Postby tribbles » Fri Feb 13, 2009 6:26 pm

I have not attached any events to the dialog form. All events within the form reference to objects on the form. i.e. change events to several check boxes and text boxes on the dialog form. There is also a finalizer referencing the dialog form as well, which seems odd.
tribbles
 
Posts: 2
Joined: Fri Feb 13, 2009 1:08 am
Location: USA


Return to ANTS Profiler Previous Versions

Who is online

Users browsing this forum: No registered users and 0 guests