Reputation: 21
I have two questions with respect to Java memory management.
When I was googling, I found some stating that static vars are stored in the permgen section of heap, but others stating that permgen is a subset of the method area. If the later is true, then are the static variables stored in method area?
Upvotes: 1
Views: 260
Reputation: 12942
in JDK 8 there is no PERMGEN any more:
With the advent of JDK8, we no longer have the PermGen. No, the metadata information is not gone, just that the space where it was held is no longer contiguous to the Java heap. The metadata has now moved to native memory to an area known as the “Metaspace”.
check below link for details and for answering your 2nd question too.
http://www.infoq.com/articles/Java-PERMGEN-Removed
Upvotes: -1
Reputation: 11858
Stack or Heap storage depends more on whether the variable is primitive, e.g. int, or Objects.
Unless your primitive is part of an object, it will most likely be created on the call stack. Otherwise it will be created as part of the object on the heap.
And as others have mentioned, there is no more PermGen in stable Java ( i.e. 8 ) and moving forward.
Do Java primitives go on the Stack or the Heap?
Where does the JVM store primitive variables?
Upvotes: 0
Reputation: 26476
Where are static and instance variables stored?
It changes from Java version to Java version, runtime to runtime. eventually, Java is written to hide away memory details such as "Where do my objects sit in memory?".
Some compilers might optimize the objects away, declare them on the stack or any place they find suitable.
So the answer is - "We can't tell for sure, does it really matter for Java anyway?"
Upvotes: 2