|
-
Nov 24th, 2002, 05:12 AM
#1
Thread Starter
Lively Member
Why forms dosn't dispose?
Hi all,
Take this sample:
Code:
public class F : Form
{
private System.Windows.Forms.Button button1;
F()
{
this.button1 = new Button();
this.button1.Click += new System.EventHandler(this.button1_Click);
}
private void button1_Click(object sender, System.EventArgs e)
{
F f = new F ();
f.Show();
}
[STAThread]
static void Main()
{
Forms.Application.Run(new F());
}
}
Into button1_Click I create a new F() but this form does not get disposed as I aspected (f go out of scope!).
The strange is that if I do this with some other class type (try with a new Class1) this get disposed!
Why they have differents behaviors?
Thanx!
-
Nov 24th, 2002, 01:46 PM
#2
Frenzied Member
use the .Close() on the form first
-
Nov 25th, 2002, 07:03 AM
#3
Thread Starter
Lively Member
[QUOTE
use the .Close() on the form first[/QUOTE]
No, I'd like to know why forms doesn't dispose automatically as any other class.
What's different?
Cya
-
Nov 25th, 2002, 10:49 AM
#4
Hyperactive Member
This is dependent on the garbage collector. Forms might get automatically promoted to the next generation. You can force a full collection by typing gc.Collect to see if the collector clears the form. I also believe that if the form is still visible, it should be on the freachable list and therefore will not be collected. Of course you can force disposal using the IDispose interface. But again, if the form is visible then this may not be permitted.
-scott
he he he
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|