Heap Space

  • For objects and data structures with longer lifespan.

  • It is a dynamic memory pool provided by the OS which can be allocated and deallocated by the programs. Therefore, the applications have control of the heap memory. It is not managed by OS.

  • Not Thread-specific. All threads can access it => Not as safe as Stack Space

  • Heap memory can lead to memory leaks.

  • Bigger than Stack Space

  • Needs Manual Memory Management.

    💡 Some virtual machines can provide Implicit Memory Management. But even an implicit memory management strategy needs to have an entity (Garbage collection) cleaning up the data.

  • Heap grow upwards to higher addresses.

  • Prone to Memory Leaks

Why choose heap data structure for this memory space?

The Heap space doesn't actually adhere to the heap data structure. It is just called so because it is a free store where memory blocks are allocated and deallocated dynamically - like a "heap" of memory blocks.


Backlinks