Skip to content
BENIBIX Learn

Heap Memory

Also known as The Heap, Dynamic Memory, Free Store

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

Think of it like

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

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.

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.

Common mistake

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

Key takeaways

  1. 1
    Lives longer. Outlasts the function.
  2. 2
    Any size. Grows as needed.
  3. 3
    Must be freed. By you or the collector.

Compare