PRB: Form Global (Static) Data Is Preserved After Form UnloadLast reviewed: June 21, 1995Article ID: Q80287 |
The information in this article applies to:
- Standard and Professional Editions of Microsoft Visual Basic for Windows, versions 2.0 and 3.0- Microsoft Visual Basic programming system for Windows, version 1.0
SYMPTOMSStatic data allocated from a form does not get deallocated when you unload the form. Static data stored in a form consists of:
RESOLUTIONAlthough the data is maintained after the form is unloaded, you cannot access this data from any other form or module. You must reload the form to access the data. To deallocate arrays, use the ReDim statement to allocate the array dynamically as needed. To unload variables, use local variables instead of static variables. If you use local variables instead of static variables, the local variables are deallocated upon exit from the procedure in which they were allocated. In version 1.0 or 2.0, Visual Basic preserves the data until the program terminates. There is no way to cause static data in the general Declarations section to be deallocated when the form is unloaded. For example, the Erase statement will not cause memory to be deallocated for arrays dimensioned in the general Declarations section. In version 3.0, you can deallocate the memory by setting the form to nothing. This forces Visual Basic to unload the module data segment (the place where the memory is allocated) as in this example:
Unload Form2 Set Form2 = Nothing STATUSThis behavior is by design.
MORE INFORMATION
Visual Basic version 1.0 Documentation ErrorsThe information on page 226 of the "Microsoft Visual Basic: Programmer's Guide" version 1.0 manual in the section titled "Unloading Forms" implies that all data in a form is lost after the form is unloaded using the Unload statement. However, this does not apply to these types of data:
Any data stored in the form is lost unless you have saved it to a file.This statement should be changed to read as follows:
Any data stored in the form, with the exception of static variables and arrays, is lost unless you have saved it to a file. The values of static arrays and variables are preserved after the form is unloaded. Steps to Reproduce Behavior
|
Additional reference words: 1.00 2.00 3.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |