Hi All,

When you close a form using myForm.Close(), does that actually destroy the
form and make it available for garbage collection?

I just want to make sure that I'm not supposed to do something to it after
to make sure that the memory can be claimed back.

I also have a timer object declared globally at the top of my main form.
I only need to use the object to control the Splash screen for the application.
After calling Stop() on it what would be the best way to get rid of it?

Thanks to anyone who can advise

Kind Regards

tce

Re: Closing a form by Tim

Tim
Sun Feb 20 10:09:48 CST 2005

Two things come to mind:

(1) The Close() method is not called for you when you close a Form that has
been shown using the ShowDialog() method. See here
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html
/frlrfsystemwindowsformsformclassshowdialogtopic1.asp) for exactly what I
mean by this.

(2) Always remember to call the Dispose() method on an object, if the method
exists, when you are done with it. This is also important in relation to
point 1. You may consider implementing the "Dispose Pattern" in your code.
See the following links for more on this.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconFinalizeDispose.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconimplementingdisposemethod.asp

--
Tim Wilson
.Net Compact Framework MVP

"thechaosengine" <na> wrote in message
news:17274632445089757807984@news.microsoft.com...
> Hi All,
>
> When you close a form using myForm.Close(), does that actually destroy the
> form and make it available for garbage collection?
>
> I just want to make sure that I'm not supposed to do something to it after
> to make sure that the memory can be claimed back.
>
> I also have a timer object declared globally at the top of my main form.
> I only need to use the object to control the Splash screen for the
application.
> After calling Stop() on it what would be the best way to get rid of it?
>
> Thanks to anyone who can advise
>
> Kind Regards
>
> tce
>



Re: Closing a form by Herfried

Herfried
Sun Feb 20 10:10:42 CST 2005

"thechaosengine" <na> schrieb:
> When you close a form using myForm.Close(), does that actually destroy the
> form and make it available for garbage collection?

Yes, if the form is not referenced elsewhere, or existing references to the
form are not accessible for the program any more (for example, circular
references). Notice that forms shown using 'ShowDialog' are not disposed
automatically when calling their 'Close' method, and thus it's suggested to
call 'Dispose' after calling close (not calling 'Dispose' will /not/ prevent
the form from being garbage collected):

\\\
Dim f As New FooForm()
f.ShowDialog()
f.Dispose()
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>