You should use Dispose on everything that implements IDisposable - Form does, because it inherits from Control.
But...you shouldn't call Dispose from inside the class instance: you should do it from outside:
MyForm mf = new MyForm();
if (mf.ShowDialog() == DialogResult.OK)
{
string path = mf.FilePath;
...
}
mf.Dispose();
If you try to dispose objects from within the object FormClosed event, the above code would fail as the MyForm instance would have been Disposed before you got a chance to read the path from it's properties.
I wouldn't worry too much about data grid views and so forth within your forms - the framework should deal with that because it constructed them, not you.
"I see, but I don't get how to call dispose on forms if not in form closed event.
This is how I show another form (in click event of a button):"
Form12 frmExO = new Form12();
frmExO.FormClosed += new FormClosedEventHandler(childForm_FormClosed);
frmExO.Show();
this.Hide();
"In childForm_FormClosed function, I have :"
this.Refresh();
this.Visible = true;
Well, you could add the dispose to the FormClosed event handler (but you'd have to disconnect the event handler to be sure it freed up the instance properly)
Or...just do this:
using (Form12 frmExO = new Form12())
{
Hide();
frmExO.ShowDialog();
}
Show();
The
using
block automatically calls Dispose for you and the visual effect will be the same.