I just read this statement in a java book saying Objects in java reside on a heap.
Is a heap used because it is the best way to store data and retrieve data fast ?
Because objects in Java often outlive the scope within which they were created, at which point the stack frame that was created for the scope ceases to exist.
Allocated heap space on the contrary is not deallocated automatically when the scope within which the object was created no longer exist.