bob wrote:
if modern OSes free up memory for processes when they die,
why does rebooting Windows XP improve performance so much more than
closing all programs?
This is an off-topic question which can easily sustain on-topic answers.
Your program's "heap" is the arena that returns storage for objects created
by 'new'.
A program's heap, on a desktop operating system, is one extent of storage
within a larger system heap. (So large OSs typically use a "heap of heaps".)
The Windows heap of heaps can push some pages of storage out to a swapper
file, to make room for other pages that are used more often.
The memory address your program uses is fake. The OS converts it to a real
address, and maybe swaps that address's contents back from the swapper file,
before the address gets as far as hardware memory.
Each time your program allocates memory from a heap, the OS might need to
allocate more storage from the heap-of-heaps for your program. All these
allocations typically follow a "first fit" algorithm. The memory manager
scans for the first block of unused storage larger than the request.
As a program allocates and deallocates, its memory fills up with small
unallocated blocks. A large, dynamic program should frequently rebalance its
objects in memory - moving them with a custom allocator, for example - to
compact the heap. That will leave larger blocks of free memory ready for the
next allocation, so that will be faster.
The Windows heap compaction system sucks.
An OS must compact its heap-of-heaps aggressively. And, in theory, this
process should be easier for an OS than a program, because the OS can move
memory simply by adjusting the real pointers that back up your program's
virtual pointers.
However, the Windows XP heap is widely known to fragment early and often.
Even if you close many programs, the OS is full of dynamic link libraries
that remain in memory after their programs discard them. When these have
data - even garbage - the OS defends them. And even if you cleared out these
libraries, I suspect that the XP heap would still be fragmented, _and_ its
representation in the swapper file would be fragmented too.
Rebooting will generally compact this heap!
Further questions on this topic belong on a newsgroup with winxp and kernel
in its name. I suspect you will learn there that Windows servers typically
schedule to reboot once a week.
--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!