Why does Java uses heap for memory allocation?

前端 未结 7 540
别那么骄傲
别那么骄傲 2020-12-09 11:15

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 ?

7条回答
  •  清歌不尽
    2020-12-09 11:29

    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.

提交回复
热议问题