Here is question :
Private void buttonFrmshow_Click(..)
{
frmEmployee f = new frmEmployee() //frmEmployee is derived from System.Windows.Form;
f.Show();
}
Now that f is local variable having scope limited to buttonclick Method,
1. Why would the Employee form be active all the time though the varible scope is finished ?
2. Will it be automatically GCed ?
3. The variable f in above code shows it’s null, still the employee form is active ? What is happening behind the scenes ?
Has it something to do with Threading ?
When new forms are created, they are added to the Application.OpenForms collection, which will keep them in scope once the local variable goes out of scope.
Closing the form will remove it from that collection and allow it to be collected.