Generally, the heap is a segment used for dynamically allocating memory for program data. As opposed to the stack, objects stored on the heap often have lifetimes that extend beyond the lexical block or function in which they are initialized.
C runtime libraries have different implementation of the heap. One of the most common implementation on Linux is the glibc heap, which is based on the ptmalloc2
implementation of malloc
(with “substantial changes”). See also emeryberger/Malloc-Implementations .
Memory Leaks
In programming languages without a garbage collector, heap allocations are handled by the program code manually. If a chunk is no longer used but not freed (as is often the case for novice C/C++ programmers), the program is said to have a memory leak, which tools like AddressSanitizer (ASan) and Valgrind can help detect via instrumenting the code. Not all memory leaks are problematic, since some objects are meant to live for the entire duration of the program execution (e.g., LLVM Types).
Assume glibc heap to be the heap implementation unless stated otherwise.