Managing Memory

Because a Palm-size PC is designed for quick access, developers of the Palm-size PC shell simplified the memory interface for their users. If an application on a desktop computer needs more memory, the shell prompts the user to shut down an application or reboot the system. In contrast, if an application on a Palm-size PC needs more memory, the shell shuts down applications without notifying the user. The following table shows the shell’s response to low memory.

Threshold
Value
Description
Hibernation 200 KB The shell sends a WM_HIBERNATE message to the application that has been inactive the longest. The shell continues to send WM_HIBERNATE messages until free memory climbs above the hibernation threshold or falls below the low-memory threshold.
Low-memory 128 KB The shell sends a WM_CLOSE message to the application that has been inactive the longest. The shell continues to send WM_CLOSE messages until free memory climbs above the low-memory threshold or when only the foreground application remains open.
Critical-memory 24 KB No new applications can be opened.

Note The threshold values may vary between devices. These values are also adjusted slightly for CPUs with 4 KB pages.

The Palm-size PC shell optimizes memory use for running applications. When the demand for memory is high, a Palm-size PC sends a WM_CLOSE message to idle applications and closes them to make room for the active application. Note that the shell never closes the desktop. Because this automatic shutdown comes without warning, you must handle the state persistence within your application, if you need to preserve your application’s state from one session to another. Typically, you archive any persistent-state variables to a temporary file after your application receives a WM_CLOSE message, but before the message is passed to the operating system. Every time the applications starts, it should check for this temporary file. If the file exists, the application should restore the application state.

To simplify Palm-size PC memory management, do not provide a Close button on your application’s toolbar. Similarly, do not enable Exit on the File menu. It is appropriate for a document within your application to have a Close button on its menu, however.

A Palm-size PC should not run multiple instances of an application. There are two reasons for this. First, running multiple instances of an application requires a lot of memory. Second, there is no way for a user to access multiple instances. On a desktop computer, a user can select between two instances of an application by clicking a different icon on the taskbar. Because the Palm-size PC shell does not show icons of running applications, this option is not available. An application may have multiple documents, but you must add this; no multiple document interface is available.