开发者

In which memory static variables,local variables are presents? [duplicate]

开发者 https://www.devze.com 2023-03-16 23:18 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicates: Whats up with static memory in java?
This question already has answers here: Closed 11 years ago.

Possible Duplicates:

Whats up with static memory in java?

What is the actual memory place for static variables?

In which memory static variables,local variables are p开发者_Python百科resents like object is leave in heap


When you do a heap dump you get all the static values. The heap dump shows that static fields are in a special object for that class. You can access this "object" in the Sun/Oracle JVM by using the Unsafe class.

While local values are on the stack, eg. a reference, any object this references in on the heap. (Unlike languages like C++)

e.g.

String hi = "hello";

The reference hi in on the stack but the Object (which is most of the memory) is in the heap.


static variables -> perm gen
local variables-> stack

0

精彩评论

暂无评论...
验证码 换一张
取 消