FIX: SCAN..ENDSCAN Causes a Memory Leak

Last reviewed: September 22, 1997
Article ID: Q125374
2.60a MACINTOSH kbprg kbfixlist kbbuglist

The information in this article applies to:

  • Microsoft FoxPro for Macintosh, version 2.6a

SYMPTOMS

Looping through a Table with a SCAN..ENDSCAN will reduce the amount of memory available to less than 200,000 bytes after a number of records have been processed. How quickly the memory is depleted depends on how many fields are in the database and on how many tables are open in addition to the table used by the loop. If the number of fields is less than five, the memory is not reduced below 200,000 bytes for a 50,000 record database.

RESOLUTION

The memory leak can be avoided by testing for low memory in the loop and calling a function to close and reopen the database. Low memory is tested for by using SYS functions SYS(1001) and SYS(1016). SYS(1001) returns the total amount of memory available to the FoxPro memory manager, and SYS(1016) returns the amount of memory being used.

STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. This problem was corrected in Visual FoxPro 3.0b for Macintosh.

MORE INFORMATION

Steps to Reproduce Problem

Open a database that has about 50,000 records and more than five fields. Then execute the following code:

   SCAN ALL NOOPTIMIZE
       MEMLEFT= VAL(SYS(1001))-VAL(SYS(1016))
       IF MEMLEFT< 200000
           CURREC=RECNO()
           WAIT WINDOW STR(MEMLEFT)+" "+STR(RECNO())
   *       DO RESTORMEM WITH CURREC
       ENDIF
   ENDSCAN

   PROCEDURE RESTORMEM
   PARAMETER WHATRECORD
   DB_NAME= ALIAS()
   USE
   USE (DB_NAME)
   MEMLEFT= VAL(SYS(1001))-VAL(SYS(1016))
   WAIT WINDOW STR(MEMLEFT)+" "+ STR(RECNO())
   GO WHATRECORD
   RETURN

In one test, the wait window appeared after approximately 33,000 records have been processed if no other databases are open. The preferred size for FoxPro was set at 8000k.

Removing the asterisk from the DO RESTORMEM line to change it from a comment to code. Now, the procedure will run correctly. This illustrates that memory is restored by closing and reopening the database. Approximately 33,000 records will be processed before the procedure is executed again.


Additional reference words: fixlist3.00b VFoxMac FoxMac 2.60a buglist2.60a
KBCategory: kbprg kbfixlist kbbuglist
KBSubcategory: FxotherGeneral
Keywords : FxotherGeneral kbbuglist kbfixlist kbprg
Version : 2.60a
Platform : MACINTOSH
Solution Type : kbfix


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.

Last reviewed: September 22, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.