1

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 presents like object is leave in heap

Community
  • 1
  • 1
subodh
  • 6,136
  • 12
  • 51
  • 73

2 Answers2

2

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.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
0

static variables -> perm gen
local variables-> stack

Suraj Chandran
  • 24,433
  • 12
  • 63
  • 94