Skip to content
BENIBIX Learn

Memory Management

Also known as Memory Allocation, Manual Memory Management

How a program gets room for its data. Then it gives the room back.

Think of it like

Think of it like borrowing books from a library. You take what you need and bring it back when you are done.

Example

Emma's C program asks for room for 1,000 numbers with malloc. When it is done with them, it calls free so the memory can be used again.

Why it matters

Getting it wrong causes crashes, slow apps and security holes. Most languages today handle it for you for that reason.

Definition

Memory management is how a program gets memory for its data and gives it back. Each value a program uses sits in memory for a while. In C you ask for memory and free it yourself. Java, Python, JavaScript and Go free it for you. That is called garbage collection. Rust has rules the compiler checks, so it frees it at the right time.

Common mistake

Thinking a language with garbage collection needs no thought about memory. You can still hold on to data you no longer need.

Key takeaways

  1. 1
    Take, then return. Every piece of memory.
  2. 2
    By hand or automatic. C by hand, Python automatic.
  3. 3
    Mistakes are costly. Crashes, leaks, holes.