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

ID: Q90145


The information in this article applies to:
  • Microsoft Visual Basic Standard and Professional Editions for MS-DOS, version 1.0


SYMPTOMS

If you repeatedly load and unload a dynamic control (a control that is a member of a control array), you may receive an "out of memory" 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 "Loading 50 Controls 100 times...Please be patient"
   FOR j = 1 to 100
      PRINT "Loop: " + 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 "ERROR: "; ERR
     PRINT "Loop Index: ";j
     x = DoEvents()
     RESUME leave

END SUB 

Additional query words: VBmsdos 1.00

Keywords :
Version : MS-DOS:1.0
Platform : MS-DOS
Issue type :


Last Reviewed: December 9, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.