# Memory Management

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

**Field:** Software Development  
**Category:** Compilers & Runtimes  
**Also known as:** Memory Allocation, Manual Memory Management

## 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.

## 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.

## 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.

## Common mistake

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

## Three principles

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

## Related terms

- [Stack Memory](https://learn.benibix.com/term/development/stack-memory)
- [Heap Memory](https://learn.benibix.com/term/development/heap-memory)
- [Garbage Collection](https://learn.benibix.com/term/development/garbage-collection)
- [Memory Leak](https://learn.benibix.com/term/development/memory-leak)
- [Memory Safety](https://learn.benibix.com/term/development/memory-safety)

---

Source: https://learn.benibix.com/term/development/memory-management
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
