Insights into heap memory


Like stack memory, heap memory is also a section in the process. This is the piece of memory that is not automatically managed, which means we have to explicitly allocate (using functions such as malloc/new), and deallocate (using functions such as free/delete) it before and after its use. It is a large pool of memory that can be used dynamically and is also known as the free store.

Heap memory associated with a process

Failure to free memory when finished using it results in a memory leak. This makes the OS think the memory is still "being used" and unavailable for other tasks. Unlike the stack, there are generally no restrictions on the heap size other than the machine's physical memory size. Data items created on the heap are accessible anywhere in the program.

Liking the course? Check our discounted plans to continue learning.