Who's referencing this form?

  • Thread starter Thread starter J
  • Start date Start date
J

J

I'm wondering why the form created in the code below stays "alive". I would
have thought that because the form variable is local to the method, that
garbage collection would get rid of it. Makes me wonder if there is a
reference to it somewhere?

// a button on one form is used to call a static method on another form, the
static method creates the form
private void btnNewForm_Click(object sender, System.EventArgs e) {
FormDBSample.ShowForm();
}


//this is the static method that creates the form
public class FormDBSample : System.Windows.Forms.Form
{
....
public static void ShowForm( ){
Cursor.Current = Cursors.WaitCursor;
try{
FormDBSample frmSample = new FormDBSample();
frmSample.Show();
}
finally{
Cursor.Current = Cursors.Default;
}
}
 
When you call Show method:
frmSample.Show();
the CLR creates a thread, and because of that frmSample
it's not collected.

Stefan
 
Back
Top