Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

storage of static instance variables [duplicate]

Tags:

java

Possible Duplicate:
What is the actual memory place for static variables?

Where does static instance variables defined in a class are stored - in heap or in Permanent generation?

JLS(both pre java SE 7 and Java SE 7) says that:

17.4.1   Shared Variables
Memory that can be shared between threads is called shared memory or heap
memory.
All instance fields, static fields and array elements are stored in heap memory.

BUT this post says that:

Success Metrics
...
Class metadata, interned Strings and class static variables will be moved from the permanent generation to either the Java heap or native memory.
...

Description
...
Class metadata and statics are allocated in the permanent generation when a class is loaded and are garbage collected from the permanent generation when the class is unloaded. Interned Strings are also garbage collected when the permanent generation is GC’ed.
...

According to above post statics are in Permanent generation area.

Which is correct??

like image 374
a Learner Avatar asked Dec 05 '25 16:12

a Learner


1 Answers

in the article

a portion of the Java heap referred to as the permanent generation

so permanent generation is in heap.

like image 91
irreputable Avatar answered Dec 07 '25 04:12

irreputable



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!