Shared Event code
The situation : My program has a main MDI Form, in which different other forms can be opened, when the application is closed, it remembers which form was closed last, and it will open this form the next time you start the application .
One of these forms has 2 toolstrips, the second toolstrip : the "search" toolstript isnt reparented to the MDI Parent, and has 2 combo's, a textbox and a button in it .
Both combo's and the textbox trigger a click on the button when the user presses "ENTER" in those controls
Considering one of my previous problems, the dispose of this form already contains :
if (this.toolStrip1 != null)
{
this.toolStrip1.Visible = false;
this.toolStrip1.Dispose();
this.toolStrip1 = null;
}
if (this.toolStrip2 != null)
{
this.toolStrip2.Visible = false;
this.toolStrip2.Dispose();
this.toolStrip2 = null;
}
When is start the application, and close this form that was automatically opened , then it stays in memory, as disposed , with following rootpath :
System.Windows.Forms KeyEventHandler
System.ComponentModel EventHandlerList.ListEntry
System.ComponentModel EventHandlerList
System.Windows.Forms ToolStripTextBox
System.Windows.Forms ToolStripTextBox.ToolStripTextBoxControl
Microsoft.Win32 UserPreferenceChangedEventHandler
Microsoft.Win32 SystemEvents.SystemEventInvokeInfo
Microsoft.Win32 SystemEvents.SystemEventInvokeInfo[]
System.Collections.Generic List<SystemEvents.SystemEventInvokeInfo>
System.Collections.Generic Dictionary<object, List<SystemEvents.SystemEventInvokeInfo>>.Entry[]
System.Collections.Generic Dictionary<object, List`1>
Microsoft.Win32 SystemEvents _handlers
Now, In my code , i had following thing happening :
this.cbVT.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtSearch_KeyDown);
this.cbComboSearch.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtSearch_KeyDown);
this.txtSearch.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtSearch_KeyDown);
(generated by VS2005)
this can be fixed in by manually unhooking the keydown event on the
toolstriptextboxitem
by adding following to your dispose
if (this.txtSearch != null)
this.txtSearch.KeyDown -= new System.Windows.Forms.KeyEventHandler(this.txtSearch_KeyDown);
It does not appear to be necessary to do the same for both combos :
if (this.cbVT != null)
this.cbVT.KeyDown -= new System.Windows.Forms.KeyEventHandler(this.txtSearch_KeyDown);
if (this.cbComboSearch != null)
this.cbComboSearch.KeyDown -= new System.Windows.Forms.KeyEventHandler(this.txtSearch_KeyDown);
The only thing i still dont understand, is why this "leak" only happens when the window was opened by the program, and not when a user opens it afterwards !
One of these forms has 2 toolstrips, the second toolstrip : the "search" toolstript isnt reparented to the MDI Parent, and has 2 combo's, a textbox and a button in it .
Both combo's and the textbox trigger a click on the button when the user presses "ENTER" in those controls
Considering one of my previous problems, the dispose of this form already contains :
if (this.toolStrip1 != null)
{
this.toolStrip1.Visible = false;
this.toolStrip1.Dispose();
this.toolStrip1 = null;
}
if (this.toolStrip2 != null)
{
this.toolStrip2.Visible = false;
this.toolStrip2.Dispose();
this.toolStrip2 = null;
}
When is start the application, and close this form that was automatically opened , then it stays in memory, as disposed , with following rootpath :
System.Windows.Forms KeyEventHandler
System.ComponentModel EventHandlerList.ListEntry
System.ComponentModel EventHandlerList
System.Windows.Forms ToolStripTextBox
System.Windows.Forms ToolStripTextBox.ToolStripTextBoxControl
Microsoft.Win32 UserPreferenceChangedEventHandler
Microsoft.Win32 SystemEvents.SystemEventInvokeInfo
Microsoft.Win32 SystemEvents.SystemEventInvokeInfo[]
System.Collections.Generic List<SystemEvents.SystemEventInvokeInfo>
System.Collections.Generic Dictionary<object, List<SystemEvents.SystemEventInvokeInfo>>.Entry[]
System.Collections.Generic Dictionary<object, List`1>
Microsoft.Win32 SystemEvents _handlers
Now, In my code , i had following thing happening :
this.cbVT.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtSearch_KeyDown);
this.cbComboSearch.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtSearch_KeyDown);
this.txtSearch.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtSearch_KeyDown);
(generated by VS2005)
this can be fixed in by manually unhooking the keydown event on the
toolstriptextboxitem
by adding following to your dispose
if (this.txtSearch != null)
this.txtSearch.KeyDown -= new System.Windows.Forms.KeyEventHandler(this.txtSearch_KeyDown);
It does not appear to be necessary to do the same for both combos :
if (this.cbVT != null)
this.cbVT.KeyDown -= new System.Windows.Forms.KeyEventHandler(this.txtSearch_KeyDown);
if (this.cbComboSearch != null)
this.cbComboSearch.KeyDown -= new System.Windows.Forms.KeyEventHandler(this.txtSearch_KeyDown);
The only thing i still dont understand, is why this "leak" only happens when the window was opened by the program, and not when a user opens it afterwards !