Why does Java uses heap for memory allocation?

前端 未结 7 508
别那么骄傲
别那么骄傲 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:40

    The problem with a stack is that you can only remove the most recent thing you added. This works fine for local variables, since they come and go as you enter and exit functions, but not so well for arbitrary data who's lifecycle doesn't follow that of individual functions. The memory heap allows you to add and remove data at will.

    0 讨论(0)
提交回复
热议问题