c# - Memory leak in ShowDialog even after disposing it -
i have created sample windows forms application contains 2 forms - form1 , form2.
form1 contains button , on click showing form2 dialogbox given below.
private void button1_click(object sender, eventargs e) { form2 form2 = new form2(); try { form2.showdialog(); } catch (exception ex) { } { if (form2 != null) { form2.dispose(); form2 = null; } } }
then checked application click on button, open form2, close it. , continued 6 times.
when checked application devpartner, showing form2 form2 = new form2();
leaked
when checked in web saying if using showdialog need dispose form after closing it,ie why tried disposing in block. still showing line leaking. can please give suggestions on leak.
as rule, when use idisposable object, should declare , instantiate in using statement. using statement calls dispose method on object in correct way, , causes object go out of scope dispose called. within using block, object read-only , cannot modified or reassigned.
the using statement ensures dispose called if exception occurs while calling methods on object.
Comments
Post a Comment