Memory Management and Multitasking
When a program is not being used, the program and its data are kept on secondary storage, such as a tablet's built-in storage or a USB stick. Secondary storage is non-volatile, so it keeps its contents when the power is off, and it has a large capacity, so it can hold many programs and files.
The CPU cannot run a program directly from secondary storage. It can only fetch instructions and data that are held in RAM (random access memory). That is why the operating system has to move programs and their data between secondary storage and RAM.
When you open a program, the operating system loads the program into RAM, together with any files it needs. For example, if you open a cooking app to view a recipe, the app's instructions and the recipe file are copied into RAM.
While the program is running, the CPU takes the instructions it needs, and the data they work on, from RAM, and anything it works out is kept there too. If you change the recipe's serving size, the new amounts are worked out and stored in RAM.
When you save your work, the operating system writes the saved data out of RAM and back onto secondary storage. When you close the program, the operating system removes it from RAM, freeing that memory for another program. The direction matters: opening loads a program into RAM, while saving writes data back out of RAM.
| Action | Direction of transfer | What the operating system does |
|---|---|---|
| Opening a program | Secondary storage to RAM | Loads the program and any files it needs into RAM |
| Saving work | RAM to secondary storage | Writes the saved data back out of RAM onto secondary storage |
| Closing a program | Removed from RAM | Clears the program out of RAM so the space can be reused |
OCR GCSE Computer Science · Memory Management and Multitasking