Hide() or Close() forms in mdi application?

  • Thread starter Thread starter Daniel Billingsley
  • Start date Start date
D

Daniel Billingsley

An example application I'm looking at uses Hide() exclusively - I've always
used Close()

My understanding would be
- Advantage of Hide is performance, as form doesn't need to be instantiated
from scratch every time it is used
- Disadvantage of Hide is memory, as once a form is opened it is never
disposed until the app ends.

Is that correct, and do you find the memory issue to be a problem in
business apps? Say where a typical user may open 20-30 different forms in
the course of a day. In my quick tests it seems that a form uses quite a
bit of memory and I don't think the user would even perceive a performance
difference.

Am I missing something though?
 
Hello Daniel,

Thanks for your post. I reviewed your description carefully, and now I'd
like to share the following information with you:

You understanding is correct that Form.Hide() sets its Visible property to
false, while Form.Close() will close the form's resources created and
dispose the form. Based on my experience, you may consider the following
things to determine when to use Form.Hide() or Form.Close():

1. How often is a Form will be re-opened? If the use will open and close a
form frequently, you may consider using Form.Hide().

2. How much time does it take to open a form? When a form is sophiscated
and it may a lot of time to initialize it (for example, getting large
amount of data from remote database to fill a DataGrid in Form_Load, etc),
you may consider using Form.Hide(), otherwise, it will affect user
experience to wait a lot of time each time for opening a specific form. If
a form can be created and displayed instantly, there is no need to use
Form.Hide().

3. You are right that Form.Hide() will keep the form in memory. There
should always be a trade-off between performance and memory usage.

Does this answer your questions?

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top