I have created a sample windows forms application which contains two forms - form1 and form2.
Form1 contains a button and on the click I am showing form2 as a dialogbox as given below.
private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
try
{
form2.ShowDialog();
}
catch (Exception ex)
{
}
finally
{
if (form2 != null)
{
form2.Dispose();
form2 = null;
}
}
}
Then i checked the application like Click on the button, then it will open form2, close it. and continued this for some 6 times.
When i checked the application with DevPartner, it is always showing Form2 form2 = new Form2();
as leaked
When i checked in the web it is saying that if we are using ShowDialog we need to dispose the form after we closing it,ie why i tried disposing in the finally block. But still it is showing that line as leaking. Can anyone please give your suggestions on this leak.