Databases Reference
In-Depth Information
FIGURE 2.14 GUI for the Advanced Browse application.
based on the selections made within the GUI. In such an occurrence, it would be most logical to
store the settings to the system registry when the button is pressed to execute the program, or, if
the form is hidden and unloaded after such a button is pressed, the constructs to save the program's
settings to the Windows Registry can be executed from the Terminate method of the user form.
This discussion prompts an explanation of a topic that is often poorly understood in the
utilization of user forms, which is the subtle but important differences between show, hide, load,
and unload methods. When the (.Show) method is invoked with respect to a form, the form pops
up while the application is executing. What is neither obvious nor intuitive, however, is that, for
the form to be shown, it must first be loaded into memory. This is accomplished by means of the
load method. However, if the show method is executed without the form first being loaded into
memory, the compiler will automatically load the form into memory. Thus:
frmRegExample.Show
is equivalent to:
Load frmRegExample
frmRegExample.Show
The problem that occurs is with the utilization of the (.Hide) method. When the hide method
is invoked, the form disappears during program execution, and this is clearly a case of “out of
sight, out of mind.” When a form is hidden, however, the form still resides in memory and can be
utilized again (with the previous settings unchanged) by invoking the (.Show) method. If this form
is never to be used again after it is hidden, it should be unloaded from memory with the unload
method. If too many forms are merely hidden in an application and not unloaded, the program will
have a “memory leak.” In other words, it will be allocating system memory and not returning it.
For small applications, this may not be a problem. However, as projects become more complex in
scope, it is important, and also good practice, to deallocate memory whenever it is no longer needed.
What will happen is that should “enough” memory leak from an application, the pool of available
memory left for the operating system and other applications to function on becomes smaller and
smaller. At some point, the amount of memory leaked reaches a critical mass where applications
or even the operating system are no longer able to function correctly, and the operating system
must be rebooted to recapture the “leaked” memory. Thus:
frmRegExample.Hide
is not equivalent to:
frmRegExample.Hide
Unload frmRegExample
Search WWH ::




Custom Search