469,572 Members | 1,324 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,572 developers. It's quick & easy.

when is the form disposed?

Dear all,
if I do myform.close() is it disposed or not?
is it correct do following?
myForm.close()
Info=SomeControlOntheForm.text
This seems to work. But am not sure that it is waterproof.
Thanks,
Boni
Nov 21 '05 #1
7 5018
"Boni" <oilia@nospam> schrieb:
if I do myform.close() is it disposed or not?
is it correct do following?
myForm.close()
Info=SomeControlOntheForm.text
This seems to work. But am not sure that it is waterproof.


It depends on how you show your form. When showing it by calling its 'Show'
method and closing it using its 'Close' method, the form will be disposed.
However, if you show your form using 'ShowDialog', it won't be disposed
automatically when it gets closed.

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

Nov 21 '05 #2
Dear Herfried,
1. what is the idea behind the dependency of destruction from the method,
how the form shown?
2. what is the good practice of taking data from the form. Should this be
done in OnFinish button handler?

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schrieb im Newsbeitrag
news:OO*************@TK2MSFTNGP09.phx.gbl...
"Boni" <oilia@nospam> schrieb:
if I do myform.close() is it disposed or not?
is it correct do following?
myForm.close()
Info=SomeControlOntheForm.text
This seems to work. But am not sure that it is waterproof.


It depends on how you show your form. When showing it by calling its
'Show' method and closing it using its 'Close' method, the form will be
disposed. However, if you show your form using 'ShowDialog', it won't be
disposed automatically when it gets closed.

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

Nov 21 '05 #3
Boni,
| 1. what is the idea behind the dependency of destruction from the method,
| how the form shown?
Form.Show (inherited from Control.Show) shows the form modelessly. The code
that displays the form will continue running while the form is being
displayed.

Form.ShowDialog shows the form as a modal dialog box. The code that displays
the form will wait until the form is closed.

Seeing as its common to set some values, ShowDialog, retrieve some values,
ShowDialog does not do a Dispose so as to allow you to retrieve values of
controls, when you are done retrieving values of controls, you need to call
Dispose.

Because of the indeterminate time when a modeless form is closed, other then
the Close event there is no real chance to call Dispose on the form...

| 2. what is the good practice of taking data from the form. Should this be
| done in OnFinish button handler?

I normally use Form.ShowDialog, then take any data from the form, then call
Form.Dispose.

For MDI children & other modeless forms, there is some command object
(button, menu, toolbar, etc...) that causes the information to be saved or
the information is implicitly saved by virtue of being bound to a
datasource.

Hope this helps
Jay

"Boni" <oilia@nospam> wrote in message
news:eP**************@TK2MSFTNGP15.phx.gbl...
| Dear Herfried,
| 1. what is the idea behind the dependency of destruction from the method,
| how the form shown?
| 2. what is the good practice of taking data from the form. Should this be
| done in OnFinish button handler?
|
| "Herfried K. Wagner [MVP]" <hi***************@gmx.at> schrieb im
Newsbeitrag
| news:OO*************@TK2MSFTNGP09.phx.gbl...
| > "Boni" <oilia@nospam> schrieb:
| >> if I do myform.close() is it disposed or not?
| >> is it correct do following?
| >> myForm.close()
| >> Info=SomeControlOntheForm.text
| >> This seems to work. But am not sure that it is waterproof.
| >
| > It depends on how you show your form. When showing it by calling its
| > 'Show' method and closing it using its 'Close' method, the form will be
| > disposed. However, if you show your form using 'ShowDialog', it won't be
| > disposed automatically when it gets closed.
| >
| > --
| > M S Herfried K. Wagner
| > M V P <URL:http://dotnet.mvps.org/>
| > V B <URL:http://classicvb.org/petition/>
|
|
Nov 21 '05 #4

I normally use Form.ShowDialog, then take any data from the form, then
call
Form.Dispose.

Do I need to destruct it explicitely? If I do not destruct it is it a memory
leak or it is removed by GC, when form variable goes out of scope?
Nov 21 '05 #5
"Boni" <oilia@nospam> schrieb:
I normally use Form.ShowDialog, then take any data from the form, then
call
Form.Dispose.


Do I need to destruct it explicitely? If I do not destruct it is it a
memory leak or it is removed by GC, when form variable goes out of scope?


'Dispose' will be called when the finalizer of the object is called.

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

Nov 21 '05 #6
Boni,
Its best to "destruct" it explicitly by calling its Dispose method.

If you don't then the GC will "destruct" it at the GC's leisure, which may
be "hours" after the fact.

Remember the GC is non-deterministic. When the form variable goes out of
scope allows the GC to collect that object, when & if the GC runs.

Hope this helps
Jay

"Boni" <oilia@nospam> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
|
|
| > I normally use Form.ShowDialog, then take any data from the form, then
| > call
| > Form.Dispose.
| Do I need to destruct it explicitely? If I do not destruct it is it a
memory
| leak or it is removed by GC, when form variable goes out of scope?
|
|
Nov 21 '05 #7
Thank you Herfried and Jay for clarifying that to me. It was my old doubt.
Now it disapears! Thanks.

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> schrieb im
Newsbeitrag news:uZ**************@TK2MSFTNGP15.phx.gbl...
Boni,
Its best to "destruct" it explicitly by calling its Dispose method.

If you don't then the GC will "destruct" it at the GC's leisure, which may
be "hours" after the fact.

Remember the GC is non-deterministic. When the form variable goes out of
scope allows the GC to collect that object, when & if the GC runs.

Hope this helps
Jay

"Boni" <oilia@nospam> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
|
|
| > I normally use Form.ShowDialog, then take any data from the form, then
| > call
| > Form.Dispose.
| Do I need to destruct it explicitely? If I do not destruct it is it a
memory
| leak or it is removed by GC, when form variable goes out of scope?
|
|

Nov 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by SamSpade | last post: by
3 posts views Thread by Dean Slindee | last post: by
5 posts views Thread by Michael.Suarez | last post: by
44 posts views Thread by Smokey Grindle | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.