craig
Tue Nov 25 09:08:11 CST 2003
I see. So the "myForm" reference goes out of scope, but the system
maintains its own reference to the form, thus keeping it alive?
"Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message
news:MPG.1a2d2a1c13f56ea989b32@msnews.microsoft.com...
> craig <e@mail.com> wrote:
> > This may sound like a dumb question, but I am hoping someone might
comment
> > on it....
> >
> > Consider the following method (assuming that Form1 is a class derived
from
> > System.Windows.Forms.Form) :
> >
> > private void MyMethod()
> > {
> > int i = 1;
> > Form1 myForm = new Form1();
> >
> > myForm.Show();
> > }
> >
> > Both of the variables, i and myForm, are local variables that should go
out
> > of scope when the method is finished executing. But the myForm variable
> > continues to live on. Is this correct? Why is the scope of form
variables
> > different than the scope of other types?
>
> It's not. The variable itself doesn't live on. However, the form
> continues to be shown until it's closed etc and there are no other live
> references to it. (The UI system will have a reference to it until it's
> closed.)
>
> --
> Jon Skeet - <skeet@pobox.com>
>
http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too