# Heap Memory

> A big part of memory. Its data can last longer than one function.

**Field:** Software Development  
**Category:** Compilers & Runtimes  
**Also known as:** The Heap, Dynamic Memory, Free Store

## Think of it like

Think of it like a big storage room. You can put boxes anywhere, but someone must clear them out.

## Definition

Heap memory is a large area for data that must outlive one function call. It also holds data whose size is not known ahead of time, like a list that keeps growing. The program asks for a piece of the heap when it needs one. That piece stays until it is freed, by you in C or by the garbage collector in most other languages. The heap is bigger than the stack but slower to use.

## Example

Jack's app loads 10,000 user records into a list. The list is too big and lives too long for the stack, so it goes on the heap.

## Why it matters

Almost every object, list and string in a real app lives on the heap. It is where most memory problems happen.

## Common mistake

Forgetting to free heap memory in C, or keeping links to it in other languages. Either way, the program slowly grows.

## Three principles

- **Lives longer.** Outlasts the function.
- **Any size.** Grows as needed.
- **Must be freed.** By you or the collector.

## Related terms

- [Stack Memory](https://learn.benibix.com/term/development/stack-memory)
- [Memory Management](https://learn.benibix.com/term/development/memory-management)
- [Garbage Collection](https://learn.benibix.com/term/development/garbage-collection)
- [Pointer](https://learn.benibix.com/term/development/pointer)

## Told apart from

- [Stack vs Heap Memory](https://learn.benibix.com/compare/stack-vs-heap-memory): Stack memory and heap memory are both parts of a running program's memory, but they hold different data. The stack is small and fast. It holds the local values of the functions running now, and they vanish when the function returns. The heap is large and slower. It holds data that must live longer or grow, until it is freed.

---

Source: https://learn.benibix.com/term/development/heap-memory
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.
