在类中定义的静态实例变量存储在堆中还是永久生成中?
JLS(前java SE 7和Java SE 7)都说:
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.
但是this帖子说:
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.
...
根据以上帖子静态在永久代区域。
哪个是正确的?
答案 0 :(得分:1)
中的文章
Java堆的一部分,称为永久生成
所以永久生成在堆中。