Java Heap Space – Understanding and Management

heapjavajvm

In Java/JVM, why do we call the memory place where Java creates objects as "Heap"?

Does it use the Heap Data Structure to create/remove/maintain the objects?

As I read in the documentation of Heap data structure, the algorithm compares the objects with existing nodes and places them in such a way that Parent object is "greater" than the children. ( Or "lesser" in case of min heap). So in JVM, how are the objects compared against each other before placing them in the heap?

Best Answer

The heap as in the memory available for dynamic memory allocation has nothing to do with the heap as in any data structure or the heap invariant (which is in fact related to the data structure). "Heap" is just a common word, and was chosen for both concepts independently (Wikipedia notes that the term was used for data structure first, but no mention of influence).

While it is probably possible to construct a memory management system which uses a heap data structure (or rather, a priority queue) in some places, I am not aware of any existing algorithm that does it, and I doubt it would be useful, outside perhaps some very specific niche.

Related Topic