Hello All, i'm confusing about the purpose of Dispose
for example, i have 2 forms and on Form1 i have a button.
on click event of button i instantiate Form2
private void button1_Click(object sender, System.EventArgs e)
{
Form2 objFrm2 = new Form2();
objFrm2.Show();
}
Then, i click the button twice. So now i have 2 objects of Form2.
on closed event of Form2, i use Dispose method
private void Form2_Closed(object sender, System.EventArgs e)
{
this.Dispose();
}
If i close Form2 once, then now i only have 1 object of Form2, right?
But, with a tool i use, it's said that i still have 2 objects of Form2.
How to really remove object of Form2 from memory allocation?
If i use GC.Collect(), the tool also said it's not recommended to call GC.Collect by our own. It's better to let the GC work on his own.
What i want is, to remove the objects i dont need anymore and i want so GC remove it from memory.