About stack and heap in JAVA(2) (二)

2014-11-24 10:33:32 · 作者: · 浏览: 1
r the duration of a program. This is good for global and static variables. Therefore, global variables and static variables are allocated on the stack.

The most important point is that heap and stack are generic terms for ways in which memory can be allocated. They can be implemented in many different ways, and the terms apply to the basic concepts.

In a stack of items, items sit one on top of the other in the order they were placed there, and you can only remove the top one(without toppling the whole thing over).

In a heap, there is no particular order to the way items are placed. You can reach in and remove items in any order because there is no clear ‘top’ item.