Microsoft KB Archive/90145

= PRB: Repeated Load/Unload of Control Can Cause Out of Memory =

PSS ID Number: 90145

Article Last Modified on 1/8/2003

-

The information in this article applies to:


 * Microsoft Visual Basic for MS-DOS 1.0

-



This article was previously published under Q90145



SYMPTOMS
If you repeatedly load and unload a dynamic control (a control that is a member of a control array), you may receive an &quot;out of memory&quot; error (error 7).



CAUSE
The problem is that Visual Basic is not able to release all memory used by the control until the current event structure has terminated. The current event structure could be an event procedure, a modal form or dialog box, or a general procedure.



RESOLUTION
To avoid this problem, do not repeatedly load and unload controls without first allowing the event structure to terminate.



STATUS
This behavior is by design.



MORE INFORMATION
The example below demonstrates this limitation.

Example
' To try this example in VBDOS.EXE: ' 1. From the File menu, choose New Project. ' 2. From the File menu, choose New Form. ' 3. Add a command button (Command1). ' 4. Set Command1.Index = 0. ' 5. Double-click on the form to return to VBDOS.EXE. ' 6. Copy the code example into the Form_Click event procedure. ' 7. Press F5 to run the program.

Sub Form_Click ON LOCAL ERROR GOTO trap PRINT &quot;Loading 50 Controls 100 times...Please be patient&quot; FOR j = 1 to 100 PRINT &quot;Loop: &quot; + STR$(j) x = DoEvents FOR i = 1 to 50 Load Command1(i) NEXT i     FOR i = 1 to 50 UnLoad Command1(i) NEXT i  NEXT j

leave:

EXIT SUB

trap:

PRINT &quot;ERROR: &quot;; ERR PRINT &quot;Loop Index: &quot;;j x = DoEvents RESUME leave

END SUB

Additional query words: VBmsdos 1.00

Keywords: kbprb KB90145

Technology: kbAudDeveloper kbVB100DOS kbVBSearch kbZNotKeyword3

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© 2004 Microsoft Corporation. All rights reserved.