malloc manages free lists on the heap: small requests are served from memory obtained with brk or sbrk, while large requests (above a threshold such as 128 KB in glibc) use mmap directly; free returns blocks to the allocator, which may coalesce neighbors, and the memory is not always returned to the OS.
A memory leak is allocated memory that is no longer reachable or needed but never freed, so usage grows over time; find leaks with tools such as Valgrind, AddressSanitizer and heap profilers, and in managed languages look for objects held by caches or global references.
Loading…