some time ago ...

I used: invoke CloseWindow, hWnd to minimize the current Window, but taskmanager says that the used space of my program is still allocated.


Space used before invoke CloseWindow, hWnd = 3000 kB.
Space after = 3000 kB.

hmmm... I looked and looked for an invoke that frees space, and I found out that the minimizebutton of the systemmenu does it right ---> freeing allocated space.

So, now i use  invoke ShowWindow,hWnd, SW_MINIMIZE  ... freeing space and i am happy :D

Later on ... I found out that if I am using it as well after an if-clause for example:

.... if eax==WM_INITDIALOG ....
.... if eax==WM_CREATE ....

invoke ShowWindow,hWnd,SW_MINIMIZE
invoke ShowWindow,hWnd,SW_SHOWNORMAL (or SW_SHOW)
invoke SetForegroundWindow,hWnd

then my program uses only half of the space allocated as before without the SW_MINIMIZE ! Even if the Window is maximized or shown ...

So i come to the conclusion that if i am using SW_MINIMIZE there are some tasks done to free up space !

Is this correct ?
Posted on 2006-12-28 02:53:06 by FairLight
When you minize your main window, Windows does a trick known as "trimming the working set size". This doesn't necessarily free up real physical memory though. You can achieve the same effect with SetProcessWorkingSetSize(process,-1,-1), but do keep in mind that this can be a false optimization since it can lead to pages of your process being swapped out, and thus having to be swapped in again later.

Use a better task manager like sysinternal's process explorer, and look at "private bytes" more closely than you look at "working set" - private bytes is the more important figure. You might also want to read this link for a better overview of what the various figures mean.

PS: CloseWindow just minimizes (even if it doesn't do the dirty trick SW_MINIMIZE does) - when you're done using a window, use DestroyWindow.
Posted on 2006-12-28 03:08:25 by f0dder
Thank you for the fast reply !

I've downloaded the PE from sysinternal's ... looks great !

In the Win32 API-Reference:
... you must use the "SetProcessWorkingSetSize" function carefully...

Ok, thanks for the hints @ fOdder ... i will test it asap ...  ;)

Posted on 2006-12-28 03:28:03 by FairLight
f0dder gets a golf clap from little h - nicely said.
Posted on 2006-12-28 05:38:25 by Homer
As long as a golf clap isn't a clap with a golf club ^_^
Posted on 2006-12-28 09:11:51 by f0dder