Skip to content

Memory Management Basics

1 min read1 lesson in topic

Learning objective

By the end of this lesson you will be able to explain RAM, virtual memory and the difference between stack and heap.

Memory is where running programs live. Understanding how it is managed explains why devices slow down and why some programs crash.

RAM vs storage

  • RAM — fast and volatile; programs load here to run
  • Storage (disk/SSD) — slower and persistent; holds files
  • A program must be copied from storage into RAM before it can execute

Virtual memory & paging

When programs need more memory than the physical RAM, the OS uses virtual memory: parts of the address space live on disk in pages and are swapped in when needed.

Stack and heap

  • Stack — function calls and local variables; fast, LIFO, fixed-size frames
  • Heap — dynamic data such as objects and big structures; grows and shrinks as needed
  • The OS and the runtime divide memory between them

Poor memory handling causes crashes (running out) and leaks (memory never released) — one reason languages with automatic memory management are popular.

Practice exercise

Check your computer's RAM and storage sizes. Why does a phone slow down when many apps are open?

Check your understanding

1. What is virtual memory?

2. Where do dynamically created objects usually live?

Self-graded — answer then check below.