In systems and programming, the heap is a region of a program’s memory used for dynamic memory allocation.

Characteristics:

FeatureDescription
PurposeStores variables that are created at runtime and need to persist beyond the current function scope.
Managed ByThe programmer or runtime environment (e.g., garbage collector in Python or Java).
LifetimeData persists until manually deallocated (C/C++) or garbage-collected (Python, Java).
AccessSlower than stack memory due to indirect referencing and fragmentation.
Example UseObjects, data structures (e.g., lists, trees), large arrays.

In Python:

a = [1, 2, 3]  # List stored on the heap, reference stored in variable `a`

The actual list is allocated on the heap; a holds a reference to that memory.