Temporary Memory in SUBprogram Is Not Deallocated after CALL (33687)






This article was previously published under Q33687

SYMPTOMS

In EXE form, the following program uses 8K of memory, not 4K as it should. The program does not seem to deallocate the temporary memory after calling the dynamic subprogram. The program works correctly inside the QB.EXE editor. To duplicate the problem, the array needs to be dimensioned after the COMMON block (to make it dynamic) and 4K of data needs to be assigned inside the subprogram, as shown.

STATUS

Microsoft has confirmed this to be a bug in QuickBasic Versions 4.00, 4.00b, and 4.50, and in Microsoft Basic Compiler Versions 6.00, 6.00b for MS-DOS and MS OS/2 (buglist6.00, buglist6.00b). This problem was corrected in Microsoft Basic PDS Version 7.00 (fixlist7.00).

MORE INFORMATION

To work around the problem, declare the array as static instead of as dynamic. You can make the array static by dimensioning it before the COMMON statement.

Note: This problem does not occur in QuickBasic Version 3.00.

The following code example demonstrates this problem:
   DECLARE SUB SaveWindow (WindowBuffer$)
   COMMON tmp$()
   DIM tmp$(10)
   PRINT FRE(""), FRE(-1)
   CALL SaveWindow(tmp$(5))
   PRINT FRE(""), FRE(-1),
   END
   SUB SaveWindow (WindowBuffer$)
     size% = 4000
     WindowBuffer$ = STRING$(size%, CHR$(0))
   END SUB
				

Modification Type: Minor Last Reviewed: 1/8/2003
Keywords: KB33687