Are the static members of a class - static variables, static blocks, and static methods stored in the Metaspace region after Java 8? If not, where are they stored?
There is no concrete information regarding the same elsewhere. All that I was able to get the information was that static variables are allocated memory at the time of class loading. But my question is where exactly is the memory being allocated - stack or heap or metaspace?
Thanks in advance!
The static variables are stored in the Heap itself.From Java 8 onwards the PermGen Space have been removed and new space named as MetaSpace is introduced which is not the part of Heap any more unlike the previous Permgen Space. Meta-Space is present on the native memory (memory provided by the OS to a particular Application for its own usage) and it now only stores the class meta-data.
The interned strings and static variables are moved into the heap itself.
For official information refer : JEP 122:Remove the Permanent Gen Space