Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
OTHER >>  HOW DO I RELEASE THE MEMORY USED BY MY VFP APPLICATION.

  Bernard Bout
  Where is Bernard Bout?
 Brisbane
 Australia
 Bernard Bout



Often after a VFP app or EXE has been running for a while, it may chew up huge amounts of memory due to caching, large select statements and lots of cursors in memory etc. You may have noticed that if the application(exe) is minimized, the memory usage drops to about 2 to 4 megs depending on what is open. This is also true of most every Windows application. Windows manages this memory usage and releases the memory when the app is minimised.

Here I have opened many windows within VFP iteslf. Check memory usage:


So how can you release this memory without actually minimizing the window whenever the memory release is needed?

Well you can do this by running this function periodically like from a timer from within the vfp application or exe:

*****************************************************************************************
* Function....:	 ReduceMemory()
* Author......:  Bernard Bout
* Date........:  05/12/2007 3:03:15 PM
* Returns.....:
* Parameters..:
* Notes.......:  reduces memory usage for vfp
*****************************************************************************************
Function ReduceMemory()

Declare Integer SetProcessWorkingSetSize In kernel32 As SetProcessWorkingSetSize  ;
	Integer hProcess , ;
	Integer dwMinimumWorkingSetSize , ;
	Integer dwMaximumWorkingSetSize
Declare Integer GetCurrentProcess In kernel32 As GetCurrentProcess
nProc = GetCurrentProcess()
bb = SetProcessWorkingSetSize(nProc,-1,-1)
*EOFUN ReduceMemory()


Memory usage has been reduced after running above function:


Note: Although I have shown the VFP.EXE process, this function works for any VFP application compiled into an EXE as well, without having to minimize the application window.

Bernard

FEEDBACK

surinder singh @ 12/7/2007 8:01:59 AM
Great!!!!!!!!!!!!!!!!!!!!
My Ratings to this article

Regards
Surinder Singh

Cetin Basoz @ 12/7/2007 3:37:34 PM
Cool. I slightly changed it to read:

SetProcessWorkingSetSize(GetCurrentProcess(),-1,-1)

PS: This would error under win9x. Warpping with an error control would be better.
I do want to rate if I can find how to:)

Jyothish KV @ 12/10/2008 2:50:27 PM
Absolutely great!!!! Very useful to everyone.

Robert J. Hwang @ 10/15/2009 9:59:04 AM
It works, It really works! So all problems are caused by the SQL cursor’s cache can not be released, right? But when I test in the .exe , not through the IIS, the memory leak doesn’t happen, so it probally is because of that, when use VFP application server (o3.dll) through IIS application pool, although the objec has been released and destroy() has been execute, but the cache that the object had used not be realeased actually, even in the destroy() use the sys(1104) to clear cache memory, so only call the ReduceMemory() function, the cache is released really.

dcNiko Vujke @ 3/12/2010 3:29:23 PM
This is really great, thank you very much.

Alex Arvanitou @ 11/13/2014 9:03:24 PM
GREAT GREAT Thanks



Your Name: 
Your Feedback: 

Spam Protection:
Enter the code shown: