Follow up question from What is a "rooted reference"?
consider this code, for a standard windows application in c#:
Program.cs:
[STAThread]
static void Main()
{
try
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
finally
{
MessageBox.Show("Bye !");
}
}
From1.cs:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.Click += new EventHandler(Form1_Click);
}
void Form1_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
What makes this form to stay as an rooted reference? Is it because of the Static Main method, i guess it is, or is it anything more to it?
If i just close the form with the X, then the message box will show "bye", but not if i click it. (because of the application.Exit()) - and i think that is strange consider the finally method in main.
So the main question, what makes the form object, stay as an rooted reference so the carbage collector not will kill it?