A garbage collector, in theory, can reclaim memory right after it goes out of scope.
Forms, however, seem to be a rare exception where they can exist beyond the scope they're created in.
For example, in an application you have two simple forms, Form1 and Form2.
A button click on Form1 creates an instance of Form2 and displays the form.
After button1_Click, frm2's scope is over, yet it still exists in memory and apparently hasn't been GCed yet.Code:public partial class Form1 : Form { private void button1_Click(object sender, EventArgs e) { Form2 frm2 = new Form2(); frm2.Show(); } }
How can this be? Does the GC make exceptions in special cases?




Reply With Quote