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

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.


  • Brian DonahueBrian Donahue Posts: 6,590 New member

    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.
  • 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.
Sign In or Register to comment.