The working set of an application is trimmed when its top-level window is minimized


When an application's top-level window is minimized through the Minimize command from its System menu or a click on its Minimize button, the operating system will trim the working set for the process. This is done to free up RAM for foreground applications. As a result of this trimming, a process may experience significantly poorer performance because its memory pages are being faulted back into RAM.

More Information

If an application minimizes its top-level window programmatically by calling the ShowWindow() API with the SW_MINIMIZE command, the working set of the process will be trimmed. However, the working set will not be trimmed when the window is programmatically minimized through the use of ShowWindow() with the SW_SHOWMINIMIZED command.

The working set of a process is the set of memory pages currently visible to the process in physical RAM. Access to this memory is very fast because the pages are resident and available for an application to use without triggering a page fault.

A process can explicitly trim its own working set by calling the SetProcessWorkingSetSize() API while passing "-1" for both the dwMinimumWorkingSetSize and dwMaximumWorkingSetSize parameters. This is essentially how the system trims the process when its top-level window is minimized. This does not mean that the memory pages used by the process are immediately discarded from RAM. In fact, these pages may remain resident for quite a while. They are simply flagged so that the system can use them for other processes as necessary. This is significantly faster than waiting on the system's standard trimming algorithm.

When a window is minimized through the Minimize command from its System menu or the Minimize button, the window is sent a WM_SYSCOMMAND message with the SC_MINIMIZE command. If the window procedure passes this message on to the system's default window procedure by calling DefWindowProc(), the default procedure will handle the message by calling ShowWindow() with the SW_MINIMIZE command. As stated earlier, this will cause the process working set to be trimmed.

You can write an application that can be minimized without having its working set trimmed. To do this, the window procedure for the top-level window should intercept the WM_SYSCOMMAND message and respond to the SC_MINIMIZE command by calling ShowWindow() directly with the SW_SHOWMINIMIZED command. It should not pass the SC_MINIMIZE command on to DefWindowProc().

Sample Code

The following code demonstrates how to write a window procedure that intercepts the WM_SYSCOMMAND message to bypass the default window procedure and prevent the process working set from being trimmed:

LPARAM lParam) {

switch (iMsg) {

if (wParam == SC_MINIMIZE) {

// programmatically minimize the window

// do not pass the minimize command on to the system's
// default window procedure
return 0;

// allow other system commands to be passed on to the
// default window procedure

// handle other window messages here...

return DefWindowProc(hWnd, iMsg, wParam, lParam);

ID do Artigo: 293215 - Última Revisão: 21 de nov de 2006 - Revisão: 1