Application Hibernation

Windows CE uses the WM_HIBERNATE message as its primary mechanism for asking applications to free memory. When freeing memory is required, the system posts the message to one or more applications, beginning with the application that has been inactive the longest. It requests memory from the active application last and does not send WM_HIBERNATE messages to invisible windows.

Note In Windows CE, hibernating is vital. All properly constructed Windows CE-based applications must have a handler for WM_HIBERNATE.

When the system brings an application to the foreground, it sends an WM_ACTIVATE message. If the hibernating application had released memory previously, the system does not restore its memory resources to the pre-hibernation state. Applications should have a WM_ACTIVATE handler that can deal with the restoration of memory resources following hibernation.

An application must take the following actions when it receives a WM_HIBERNATE message:

As the amount of available memory drops, the system posts WM_HIBERNATE messages at an increasing rate. If the system reaches a situation where a call to VirtualAlloc is about to fail, it tries to free pages by shrinking stacks. The system shrinks stacks in first-in, first-out order to minimize the risk of a stack fault, which causes an application to fail. If the system cannot free any stack pages, VirtualAlloc fails and the function is returned to the application as a failed function call.