Moveable segments can also be marked as discardable. This means that when Windows needs additional memory space, it can free up the area occupied by the segment. Windows uses a ”least recently used“ (LRU) algorithm to determine which segments to discard when attempting to free up memory.
Discardable segments are almost always those that do not change after they are loaded. Code segments of Windows programs are discardable because (in most cases) programs do not modify their code segments. Indeed, code segments cannot be modified in protected mode. When Windows discards a code segment, it can later reload the code segment by accessing the .EXE file. Most of Windows' own code in the USER and GDI modules and various driver libraries is also discardable. (The KERNEL module is fixed. This is the module responsible for Windows' memory management.) Resources—such as dialog box templates, cursors, and icons—also are often marked as discardable. Again, Windows can simply reload the resource into memory by accessing the .EXE file that contains the resource.
Sometimes you'll see that a disk is being accessed when you move the mouse from the client area of one program to the client area of another. Why is this? Windows has to send mouse movement messages to the second application. If the program's code to process this message is not currently in memory, Windows must reload it from the disk file. If you have several large Windows programs loaded simultaneously, you may witness some ”thrashing“ (an inordinate amount of disk activity) as you move from program to program. Windows is reloading previously discarded segments.
Discardable segments must also be moveable segments, because discardable segments can be reloaded in a different area of memory than the area they occupied earlier. However, moveable segments are not always discardable segments. This is usually the case with data segments. Windows cannot discard a program's automatic data segment, because the segment always contains read-write data and the stack.
Many people are under the impression that Windows also swaps memory—that is, that when Windows needs additional memory, it saves some portion of memory on the disk and reloads it at a later time. For Windows programs, this is true only when Windows is running in 386 enhanced mode. Windows swaps memory to disk only when running non-Windows programs (otherwise known as ”old applications“). When Windows loads these old applications from disk back into memory, it must load them at the same memory address they occupied previously.