Posts filed under ‘Winform’

Memory Leak when disposing of .Net child Winform with mainmenu

I had an application recently that has a child window with a mainmenu. I begin noticing that memory weren't being released even when I dispose of the child form. I decided to do an experiment by creating a simple app that creates 10 child window and closes then each time a button is press. The form are disposed of immediately after they are closed. I then examine the run under the CLRProfiler.

What seems to be happening is that the event handler for the form prevent the child form from being garbage collected. However, this is technically not a leak, since after about 250 form objects are on the heap, some of the child forms are cleaned up. It's just that the CLR seems to be holding on to the child form longer than normal due to the menuitem event handler.

I tried this under VS.Net 2005 and notice that the problem does not occur, so it only affects VS.Net 2003. It's also possible that Microsoft may have a patch for this problem for VS.Net 2003, but I did not see it mentioned when I search MSDN.

June 18, 2006 at 5:23 pm Leave a comment

Winform Validation: Keypress vs TextChanged

Suppose I want to run a validation routine when the text changed, one could have it call an validateField either by keypress (keydown, keyup, etc) or TextChanged.

private void validateField(){

if (HasPeriod(this._myfield)

{

     this._myFormErrorProvider.SetError(this._myfield, "Field must not have periods.");

}

else

{

this._myFormErrorProvider.SetError(this._myfield, "");}}

The routine uses a simple string search using val.IndexOf() to check if the string contains a period. What I have notice is that if I do this in a keypress event and I press a period key. The period won't be notice until I press another key. With a TextChanged event, the period is noticed right away.

May 1, 2006 at 8:56 pm Leave a comment


Calendar

May 2017
M T W T F S S
« Jun    
1234567
891011121314
15161718192021
22232425262728
293031  

Posts by Month

Posts by Category