Newcomers to Winforms and WPF .net applications are sometimes alarmed about the amount of memory they are shown to use in Task Manager.
When these applications run in a Terminal Server environment (or Citrix) the memory consumption seems to add up. I have heard of products that somehow reduce the memory consumption of processes in this environment. The makers of these products claimed to be able to fit more processes on the one server. I made it my mission to find out how these applications may work.
Minimizing as a Lifestyle
A hint as to how they may work is the behaviour of the application when it’s minimised. Memory usage definitiely goes down. When the application is normalised, memory consumption goes back up, but not as much.
For example, with a WPF application with a single window and no controls, according to Task Manager uses 27388K. On minimise of the application, memory consumption goes down to 3128K. Normalising the application, the memory consumption goes back to 8306K.
Apparently minimizing the application makes a call to the Win32 api call SetWorkingSet, this is what causes the apparent memory reduction. Looking at the history of Windows, this behaviour makes sense. In the Windows 3.1 user interface, minimizing applications was the way a user typically indicated to Windows they were switching to something else.
Something I wonder about is whether this is still appropriate? Since Windows 95 introduced the Task Switcher, do people still minimise? Another question. In the Terminal Server environment, is the call being made when a user becomes idle? Should it be?
Microsoft’s documentation of the call indicates that application calls to SetWorkingSet are not necessary, as the operating system will manage the memory as required. Is this automatic memory management assuming the Windows 3.1 usage pattern?
Two years ago I created a prototype that called SetWorkingSet when an application had become idle for a certain amount of time. It seemed to work well, but I had no evidence it helped system performance particularly.
I apologise for the inconclusive nature of this post, but I thought I would put my musing out there in case others had anything to comment.
|Share this post :|