"Not enough memory to complete this operation" error occurs after repeatedly showing modal form with large menu

Article translations Article translations
Close Close
Article ID: 957235 - View products that this article applies to.
Expand all | Collapse all
Source: Microsoft Support

RAPID PUBLISHING

RAPID PUBLISHING ARTICLES PROVIDE INFORMATION DIRECTLY FROM WITHIN THE MICROSOFT SUPPORT ORGANIZATION. THE INFORMATION CONTAINED HEREIN IS CREATED IN RESPONSE TO EMERGING OR UNIQUE TOPICS, OR IS INTENDED SUPPLEMENT OTHER KNOWLEDGE BASE INFORMATION.

Action



You have a Visual FoxPro application that contains a menu containing 40 or more bars. One of the bars over the 40th references a popup submenu. You instantiate then release a modal form repeatedly. 

Result



You may eventually encounter this error: 

There is not enough memory to complete this operation.

This is Visual FoxPro error 43.

Cause

A memory leak occurs with memory from the desktop heap. Once the desktop heap memory is exhausted, the error will occur. This is a bug is in Visual FoxPro, and the Visual FoxPro runtime.

Resolution

Reduce the number of menu bars to less than 41.

More Information



The default size of the desktop heap is 3072 KB in 32-bit Windows versions and 20480 KB in 64-bit Windows versions. A larger desktop heap size will delay, but not prevent, the occurrence of the error.

You can use Desktop Heap Monitor to view or track the desktop heap usage.

Desktop Heap Monitor is available at http://www.microsoft.com/downloads/details.aspx?familyid=5CFC9B74-97AA-4510-B4B9-B2DC98C8ED8B&displaylang=en.  

Steps to Reproduce the Behavior:

1. Run the following code from a program file in Visual FoxPro:

clear
erase testxx.pj?
LOCAL aobj[1], xx as form
DELETE FILE testxx.sc?
CREATE FORM testxx NOWAIT
=ASELOBJ(aobj,1)
xx = aobj[1]
xx.height = 50
xx.width= 50
xx.autocenter = .t.
xx.WindowType= 1
KEYBOARD 'Y' CLEAR
RELEASE WINDOW 'Form Designer'

CREATE PROJECT testxx nowait
TEXT TO lcText NOSHOW

do menuproc
?Version()
?'press f5 to exit, f8 for error'

on key label f5 clear events
on key label f6 do form testxx
on key label f8 do doform
read events
return

procedure doform
if Len(GetEnv("CommonProgramW6432")) > 0
?"64 bit"
nLimit = 5000
else
?"32 bit"
nlimit = 1500
endif
for lni = 1 to nlimit
keyboard '{ctrl+f4}'
do form testxx
set message to alltr(Str(lni))
endfor
endproc

procedure menuproc
SET SYSMENU TO
SET SYSMENU AUTOMATIC

DEFINE PAD _2ev199x75 OF _MSYSMENU PROMPT "\<test" COLOR SCHEME 3 ;
KEY ALT+T
ON PAD _2ev199x75 OF _MSYSMENU ACTIVATE POPUP test

DEFINE POPUP test MARGIN RELATIVE SHADOW COLOR SCHEME 4

for lni = 1 to 41 step 2
DEFINE BAR lni OF test PROMPT "test"+Alltrim(Str(lni))
DEFINE BAR lni+1 OF test PROMPT "\-"
endfor

* change following to 39, problem does not happen
#define BAR_TO_USE 41
lcPromptName = "Test"+Alltrim(Str(BAR_TO_USE))
ON BAR BAR_TO_USE OF test ACTIVATE POPUP &lcPromptName
DEFINE POPUP &lcPromptName MARGIN RELATIVE SHADOW COLOR SCHEME 4
* leaks faster with more bars in this popup
for lni = 1 to 30
DEFINE BAR lni OF &lcPromptName PROMPT "ww"+Alltrim(Str(lni))
ON SELECTION BAR 1 OF &lcPromptName wait window
endfor
endproc

endtext
DELETE FILE testxx.prg
?STRTOFILE(lcText,'testxx.prg',0)
_vfp.ActiveProject.files.add('testxx.prg')
if !_vfp.ActiveProject.Build('testxx.exe',)
    =MessageBox("failed")
else
    _vfp.ActiveProject.close
    ?"done"
    lcRuncmd ="! /n "+Addbs(_vfp.defaultfilepath)+'testxx.exe'
    &lcRuncmd
endif

return


2. After the application is created, it will execute, and appear in a separate window. Once it does, press F8.

 

Results:

1. Eventually you get "Not enough memory to complete this operation." (error 43). The iteration count shows in the status bar; it will fail about 1150 for 32 bit OS and 4000 for 64 bit OS.

2. The same behavior occurs in VFP versions back to VFP7.

3. Desktop heap is being exhausted.

4. Problem only occurs if you have a popup with > 40 bars, and a bar over 40 has a popup associated.

DISCLAIMER

MICROSOFT AND/OR ITS SUPPLIERS MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY, RELIABILITY OR ACCURACY OF THE INFORMATION CONTAINED IN THE DOCUMENTS AND RELATED GRAPHICS PUBLISHED ON THIS WEBSITE (THE “MATERIALS”) FOR ANY PURPOSE. THE MATERIALS MAY INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS AND MAY BE REVISED AT ANY TIME WITHOUT NOTICE.

TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, MICROSOFT AND/OR ITS SUPPLIERS DISCLAIM AND EXCLUDE ALL REPRESENTATIONS, WARRANTIES, AND CONDITIONS WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO REPRESENTATIONS, WARRANTIES, OR CONDITIONS OF TITLE, NON INFRINGEMENT, SATISFACTORY CONDITION OR QUALITY, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE MATERIALS.

Properties

Article ID: 957235 - Last Review: August 26, 2008 - Revision: 1.0
APPLIES TO
  • Microsoft Visual FoxPro 7.0 Professional Edition
  • Microsoft Visual FoxPro 8.0 Professional Edition
  • Microsoft Visual FoxPro 9.0 Professional Edition
Keywords: 
kbnomt kbrapidpub KB957235

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com