The operating system takes care of memory management. It does this in 4 different ways:
Virtual memory: Part of the hard drive and used when the computer doesn’t have enough RAM to hold all the data and programs being used at that time. It stores the least used programs and data in the virtual memory which can still be accessed, but is slower. Adding more RAM reduces the use of virtual memory and makes the performance of the computer better. The operating system must keep track of which applications are in use, and relocate them appropriately.
Peripheral management and device drivers: A peripheral device is hardware that interacts with the computer like a mouse of keyboard. The operating system must ensure that peripheral devices work together correctly by downloading device drivers, updating them regularly and storing them appropriately so they work correctly.
Defragmentation: Data is scattered on the hard drive. Defragmentation software provided by the operating system reorganises the data so it is easier to access and is quicker to navigate by storing parts of programs and data close to each other.
Multitasking: An operating system must make sure that it is easier for multiple programs to be used at the same time as well as optimising individual programs to run faster by making sure that the CPU is in use as much as possible. When there are several processes sharing one processor they are given different priorities depending on how much CPU power each program needs.