No this is not JAVA talk ;)

Im currious if anyone knows of an api to kick the OS into gear and reclaim/defragment its system memory.

I found that repeated calls for bitmap resources (createdDIBsection) and then deleteing the bitmap, chokes the memory temporarily, and in "few second" all the memory is reclaimed.

I was wondering if i could help the OS along and say now *is* a good time to do such things??

In case your wondering, im guaging this by using the START+BREAK combo to get to the system properties and looking at the performance.

Thanx for any thoughs!
:alright:
NaN
Posted on 2002-05-06 02:05:57 by NaN
You can try this


invoke GetCurrentProcess
invoke SetProcessWorkingSetSize,eax,-1,-1

I use this in a program and it seems to reclaim memory
Posted on 2002-05-06 02:54:11 by WinCC
Yes.

If both dwMinimumWorkingSetSize and dwMaximumWorkingSetSize have the value 0xffffffff, the function temporarily trims the working set of the specified process to zero. This essentially swaps the process out of physical RAM memory.

Giovanni
Posted on 2002-05-06 16:54:47 by sch.jnn
If you allocate enough new memory, windows will reclaim leaked memory.

Put the following in a blank .vbs file and run it. (You can set the # up to the amount of ram you have)
Mystring=Space(16000000)

That should flush out wasted memory.
Posted on 2002-05-06 22:10:13 by grv575
With "wasted" memory you mean some memory allocated but then not freed by an already exited (or crashed) process?
What other common cases of memory leaks there usually be under this OS?

Moreover.. often I heard about RAM fragmentation.. and that it slows down the system. I imagine big blocks of logical memory scattered in various 4KB pages around physical memory. Still I don't see how this would impair so much performance, though.

I get the doubt there's some mechanism of Win32 that I don't fully get.
Posted on 2002-05-07 04:57:26 by Maverick
Im 99% certian there is no memory leaks. The algo's are clean and tidy, and well commented here. Im pretty anal about such things. And my memory seems to agree here, only its 'sluggish'.

I dont know if you dont loaded my lasted version of my edit control. But there is a selector scroll bar to dynamically select the level of alpha blend you want, so you can read the text better.

Every selection, creates a DIB and does 'math' on it, then blt's the pic to a final 'static' destination. (Static being, already created and not destroyed, just overwritten). When the math is finished, i clean up my mess, and delete the dib/rc's used.

Problem is, if i get crazy with the slidder (rapid movements ~ 10 sec). The system resources take a huge 'spike' like hit. This is because each position goes through this process again (create big, use(alpha setting), copy out, and destroy). I've even gotten system messages from it (no memory left).

But if i wait (with our without the memory message), *eventually* the memory restores to its original amount before i got crazy with the alpha settings. Which back my claim that im destroying what mess i create.

This is why i posted this thread. I have two choices, make it 'less' dynamic, and send messages at intervals the system can keep up with, or somehow, tell the OS to do 'garbage cleaning' after i destroy everything (but before the next message comes).

Again thanx for your thoughts on this.
:alright:
NaN
Posted on 2002-05-07 09:21:31 by NaN
Looks like a *resource* as opposed to just a memory leak. I'm assuming you're testing on win98. Try win2000/xp.

You get that out of memory message from win9x not freeing resources correctly and there's nothing you can do short of rebooting.

The memory scavengers/defragmenters won't help with leaked resources and I highly doubt there's any api function to deal with it either.
Posted on 2002-05-09 01:37:27 by grv575
:-/

Hmm, well i can say it *does* get reclaimed. But not as fast as im allocating/deallocating them. I think i have an alternate solution in mind, based on Maverick's tips with the stack.

NaN
Posted on 2002-05-09 04:11:09 by NaN