On Thu, 26 Jul 2007 12:49:05 -0700, Goose14 <gu*******@gmail.comwrote:
string SelectedSite
using (SiteLauncher SiteLaunch = new SiteLauncher()
{
SiteLaunch.ShowDialog();
SelectedSite = SiteLaunch.SelectedPokerRoom; //this is
a property that returns a string
}
My question is, if after the using block is over, will the SiteLaunch
object be able to dispose itself? Or does it stay alive because of the
open reference with SelectedSite. If this is the case, is there a
better way of doing this?
SelectedSite doesn't refer to the SiteLauncher instance. It refers to the
string that the SiteLauncher instance returned. So I don't see any reason
that SelectedSite would in any way affect the lifetime of SiteLaunch, or
in any way be affected by the disposal of SiteLaunch.
That said, suppose you have actually referenced the SiteLauncher instance
somehow and retained that reference outside the "using" statement block.
For example, instead of referencing something simple like a string that is
immutable and doesn't contain a reference back to anything else, perhaps
you had a reference to something that was modified by SiteLauncher during
disposal, or which kept a reference to the SiteLauncher object.
Then you would in fact have a problem. My understanding is that not only
"will the SiteLaunch object be able to dispose itself", that's exactly
what the "using" statement always does. It always disposes the object,
before exiting the "using" statement. So if the retained object was
modified by disposal of the SiteLauncher instance, or you were somehow
able to get the SiteLauncher instance reference from the retained object,
that would be an issue. The simple answer is to not do that. :)
Pete