Where are static variables stored in java?
This question already has an answer here:
In the JVM memory model the reference to and value of static variables are both stored in the method area which itself is in the heap.
The method area is created on virtual machine start-up. Although the method area is logically part of the heap, simple implementations may choose not to either garbage collect or compact it.
https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-2.html#jvms-2.5.4
From JVM Documentaion:
Method Area
The Java Virtual Machine has a method area that is shared among all Java Virtual Machine threads. The method area is analogous to the storage area for compiled code of a conventional language or analogous to the "text" segment in an operating system process. It stores per-class structures such as the run-time constant pool, field and method data, and the code for methods and constructors, including the special methods (§2.9) used in class and instance initialization and interface initialization.
The method area is created on virtual machine start-up. Although the method area is logically part of the heap, simple implementations may choose not to either garbage collect or compact it. This version of the Java Virtual Machine specification does not mandate the location of the method area or the policies used to manage compiled code.
链接地址: http://www.djcxy.com/p/82872.html上一篇: 静态成员是否有助于记忆效率?
下一篇: 在java中存储静态变量的位置?