FIX: "Too Many Names Used" Error with Repeated AddObject()/RemoveObject() Calls (299322)



The information in this article applies to:

  • Microsoft Visual FoxPro for Windows 5.0
  • Microsoft Visual FoxPro for Windows 5.0a
  • Microsoft Visual FoxPro for Windows 6.0

This article was previously published under Q299322

SYMPTOMS

When a program makes repeated calls to the AddObject and RemoveObject methods, the following error message may be received:
Too Many Names Used

CAUSE

Visual FoxPro is not releasing unused names from the internal names table used to keep track of created objects.

STATUS

This problem was corrected in Microsoft Visual FoxPro version 7.0 for Windows.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Paste the following code in a new program:
    ON KEY LABEL F5 DO CleanUp
    CLEAR ALL
    CLEAR
    
    LOCAL lcVarName,  lni, loCont
    PUBLIC glKeepGoing
    loCont = CREATEOBJECT("Container")
    glKeepGoing = .T.
    lni = 0
    
    DO WHILE glKeepGoing
    	lni = lni+1
    	lcVarName = "ln" + SYS(2015)
    	loCont.ADDOBJECT(lcVarName ,"Line")
    	loCont.REMOVEOBJECT(lcVarName)
    	IF MOD(lni,500) = 0
    		? lni, SYS(1011), SYS(1016)
    		_CALCMEM = lni && The Calculator Memory will persist 
                                   && through the following CLEAR ALL.
    		CLEAR ALL
    		LOCAL loCont, lni, lcVarName
    		glKeepGoing = .T.
    		loCont = CREATEOBJECT("Container")
    		lni = INT(_CALCMEM)
    	ENDIF
    ENDDO
    
    PROCEDURE CleanUp
    	glKeepGoing = .F.
    	ON KEY LABEL F5
    ENDPROC
    					
  2. Save and then run the code (the program name is not important).

    You can press F5 at any time to end the running program. The numbers printed to the screen are loop iterations. They show the value of SYS(1011) (Number of Memory Handles) and the value of SYS(1016) (User Object Memory Use). The error occurs when the number of iterations reaches around 64000.
(c) Microsoft Corporation 2001, All Rights Reserved. Contributions by Trevor Hancock, Microsoft Corporation.


Modification Type:MajorLast Reviewed:10/16/2002
Keywords:kbBug kbDSupport kbOOP kbvfp700fix KB299322