WindowsForm Resources

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Could someone please comment on the validity the following statement:

1. A Windowsform is created at runtime, and the user interacts with it.
2. The window is closed either by user action or the .Close method being
called.
3. The instance of the myForm class is stored as on object variable in the
program.

Conclusion:

The only resources being saved are a bunch of properties for that form
object, and if that form object later calls the .show method, the form is
re-created from scratch. In other words, all 'expensive' resources that deal
with the actual displaying of the form are released when closed, right?
 
Zorpiedman,

What is the reason you ask this and what do you mean with saved?

Cor
 
Cor -
I ask becuase I am doing this exact thing, but the form is being re-created
over and over again (different each time) and I am storning each new form
object so it can just be re-opened when needed.

What I want to make sure of is that the 'expensive' resources (GDI?) are
dropped.

In VB-6, you would never do such a thing because retaining a reference to
the form object would retain a reference to all of it's resources including
those that put it on the screen. I always had to extract any basic variables
from the form then set the form to nothing to be sure I was not holding a
reference to a UI object... am I making sense?

-Zorpy
 
Zorpiedoman,

A VB6 forms act completly different from a VBNet form.

In VBNet is a form a class as every other class.
Setting its reference to nothing does nothing, because there are mostly a
lot of objects referenced too it, which would be removed by its base class
(which implements Idisposable) when it closes.

http://msdn.microsoft.com/library/d...ref/html/frlrfsystemidisposableclasstopic.asp

When your form is not removed from screen, than you can show us maybe some
code.

However basicly the
dim frm as new form creates a form (see for that the sub new in a form)
frm.show does only show it.

(While there is something written about a showdialogf orm, however not
really clear for me on MSDN Based on that on MSDN is often told that it
should be disposed. I doubt about that, however do it, because I am not
sure).

I hope that this gives some idea's

Cor
 
Zorpiedoman said:
Could someone please comment on the validity the following statement:

1. A Windowsform is created at runtime, and the user interacts with it.
2. The window is closed either by user action or the .Close method being
called.
3. The instance of the myForm class is stored as on object variable in
the
program.

Conclusion:

The only resources being saved are a bunch of properties for that form
object, and if that form object later calls the .show method, the form is
re-created from scratch. In other words, all 'expensive' resources that
deal
with the actual displaying of the form are released when closed, right?

When calling 'Close' on a form shown by calling its 'Show' method, the form
is disposed automatically, which means that all unmanaged ressources
obtained by the instance of the form are released. If you are showing the
form as a dialog by calling its 'ShowDialog' method, you will have to call
its 'Dispose' method separately after closing the form.
 

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