when is the form disposed?

  • Thread starter Thread starter Boni
  • Start date Start date
B

Boni

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
 
Boni said:
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.
 
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?
 
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

| 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?
|
Newsbeitrag
| | >> 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/>
|
|
 
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?
 
Boni said:
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.
 
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

|
|
| > 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?
|
|
 
Thank you Herfried and Jay for clarifying that to me. It was my old doubt.
Now it disapears! Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top