Windows Mobile 6.5 Auto-Close Memory Algorithms

Windows Mobile 6.5 relied on a tiered, event-driven memory management system to automatically reclaim physical RAM when system resources were depleted. Built on the Windows CE 5.2 kernel, the operating system utilized a combination of threshold-based triggers, cooperative process hibernation, and a deterministic Least Recently Used (LRU) termination sequence to prevent system crashes without requiring manual task management from the user.

Memory Architecture and Trigger Thresholds

The Windows CE 5.2 kernel architecture enforced a strict 32 MB virtual address space per process across a maximum of 32 concurrent process slots. When physical RAM ran low, the system kernel monitored memory availability against pre-configured kernel thresholds:

  • Normal Threshold: System operates without intervention.
  • Low Memory Threshold: Triggered when free physical RAM falls below a designated safe zone (often between 1 MB and 2 MB, depending on OEM configurations).
  • Critical Memory Threshold: Triggered when memory depletion threatens fundamental OS stability (typically below a few hundred kilobytes).

Phase 1: The Cooperative Hibernation Request

When free memory crossed the low memory threshold, the shell avoided immediately terminating applications. Instead, it broadcast the WM_HIBERNATE message to top-level windows.

Under this cooperative model:

  • Applications running in the background were expected to intercept WM_HIBERNATE.
  • Developers were instructed to free non-essential resources, flush caches, release large bitmaps, and discard cached UI components.
  • If applications reduced their memory footprints sufficiently to push available RAM back above the threshold, the auto-close sequence was halted.

Phase 2: Graceful Least Recently Used (LRU) Termination

If the WM_HIBERNATE broadcast failed to recover enough physical memory, the Graphics, Windowing, and Events Subsystem (GWES) initiated the auto-close algorithm.

This algorithm operated on a strict Least Recently Used (LRU) policy derived from the window z-order and user interaction history:

  1. Selection: The OS examined all running top-level tasks and ranked them based on when the user last brought them to the foreground.
  2. Protection Checks: The system evaluated process immunity (the active foreground application, system-critical processes, and telephony services were excluded).
  3. Targeted Graceful Shutdown: The oldest background application in the LRU queue was sent a WM_CLOSE message, giving the software an opportunity to save state and exit cleanly.
  4. Re-evaluation: After a brief waiting interval, the OS re-checked free memory. If free RAM remained below the threshold, the algorithm targeted the next oldest application in the LRU chain.

Phase 3: Forced Kernel Termination

When memory reached the critical threshold, or if an application failed to terminate after receiving a WM_CLOSE message within a specific timeout period, the kernel intervened directly.

The OS escalated from graceful window closures to forced termination:

  • The kernel called TerminateProcess on the offending background process.
  • All virtual memory allocations, handles, and threads associated with that process slot were forcibly purged from RAM immediately.
  • The LRU evaluation continued killing processes until the system returned to an operational state.

Protected Processes and Exceptions

Certain core components were exempt from the auto-closing algorithm:

  • System Services: Core operating system processes, including nk.exe (the kernel), gwes.exe, device.exe, and filesys.exe.
  • Telephony and Radio Stacks: The phone dialer interface (cprog.exe) and cellular radio services were prioritized to prevent missed calls or network disconnections.
  • Active Foreground Application: The application currently being viewed and interacted with by the user was kept alive unless the application itself caused an unrecoverable out-of-memory exception.