Q33687: Temporary Memory in SUBprogram Is Not Deallocated after CALL
Article: Q33687 Product(s): See article Version(s): 4.00 4.00b 4.50 Operating System(s): MS-DOS Keyword(s): ENDUSER | buglist4.00 buglist4.00b buglist4.50 B_BasicCom | mspl13_basic Last Modified: 13-DEC-1989 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. Microsoft has confirmed this to be a problem 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). 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
THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.
Copyright Microsoft Corporation 1986-2002.