By definition, all PCs of all form factors have limited physical memory. The challenges of managing memory do not change when you add more physical memory, so long as you are actually running more programs that request more memory.
Several classes of modern software will continue to evolve to use more and more memory – photo editing of giant RAW images, in-memory databases, very large spreadsheets, and so on. Whether these have WinRT-based implementations or desktop implementations, the OS needs to evolve to manage these ever-increasing memory requests.
“WinRT is an opportunity for programmers to use an API that allows access to all the memory they need while putting the user first in terms of responsiveness and getting work done.”
Windows 8 allows Metro style apps to stay suspended in the memory of a PC when not in use. That means that when a user wants to restart a Metro app, it should begin again with almost no lag.
In a April 17 blog post, Bill Karagounis, group program manager on Fundamentals team details the behind-the-scenes efforts to reclaim memory even when Windows 8 Metro style apps are suspended, and how this all happens without developers needing to worry.
Karagounis writes, “Windows 8 will try to keep the most important (frequently accessed) pages of memory in the app’s working set.” However, Metro apps have a different way of handling memory allocation. “Starting with the Windows 8 Consumer Preview, whenever Windows detects memory pressure on the system, it will repurpose nearly all the memory that suspended Metro style apps would otherwise hold onto. Windows 8 can reclaim this memory without having to terminate an app,” said Karagounis.
He writes Metro style apps, however, are different from desktop apps, in that they are usually suspended whenever they are no longer in the foreground. When they’re suspended, they aren’t touching ANY of their memory.
“In Windows 8 Consumer Preview, we can efficiently write the whole (private) working set of a suspended Metro style app to disk, in order to gain additional memory when the system detects pressure. This process is analogous to hibernating a specific app, and then resuming it when the user switches back to the app. We’re taking advantage of the suspend/resume mechanism of Metro style apps to empty or re-populate an app’s working set,” explains Karagounis.
The screenshot below highlighted a few suspended Metro style apps with memory held in their working sets. The apps are running on a PC with 2GB of RAM. The Metro style apps were in the background, and therefore Windows suspended them.
In the next screenshot, he opened some more apps in order to introduce additional memory pressure and induce the behavior described above. As you can see, Windows emptied the working sets of the suspended Metro style apps (highlighted). This example, liberated over 250 MB of physical RAM for other apps to use without shutting down the suspended apps.
Responsiveness when reading the working set back in – a test for this new facility is how responsive a suspended app is after its working set contents are emptied and you decide to switch back to the app. A Windows 8 app that’s suspended on a disk may take a little longer to be restored once a user decides to return to it, depending on how large its working set is.
“On a low-end machine, with a high memory load, it’s hard to perceive a difference in responsiveness when switching back to the app whose working set was being read from disk compared to when its working set was still in memory. Your mileage will vary though: the larger the working set, the longer it will take to read-in from disk,” he said.
Adding, Microsoft is also “continuing to reduce the amount we have to write to disk for Metro style apps and further optimizing this feature.”
“This functionality is something that everyone with the Consumer Preview release can try for themselves,” Karagounis concludes. “Just open up a number of Metro style apps and desktop apps to generate some memory pressure, and then switch back to a suspended Metro style app that has had its working set emptied.”
Note: Windows will still close Metro style apps if memory gets into the critical range. However, this feature will enable a system to run more applications before getting to that point.
Watch the video below to the features in action: