Java Memory Management: Drill down into Java memory areas
The above article for the Java Memory Management mechanism is very detailed, here we just to facilitate the understanding of the later content, the Java memory mechanism to do a simple comb.
Program counter: The line number indicator of the byte code executed by the current thread, the next byte code instruction to be executed by the virtual machine, and the basic functions such as branching, looping, jumping, exception handling, thread recovery, etc., need to rely on changing the value of this counter to complete.
Stack: Saves a local variable, a reference, and is freed when the method call ends. when each method is executed, a stack frame is created at the same time to store the local variable table, the Operation Stack, the dynamic link, the method exit
and other information. Each method is called until the completion of the process, corresponding to a stack frame in the virtual machine stack from the stack to the process of the stack. Divided into virtual machine stacks and local method stacks
Heap: Created at virtual machine startup, shared by all threads, stores object instances, and managed by the Java Garbage collector (GC) for memory release.
Method area: Used to store class information that has been loaded by the virtual machine, constants, static variables, code compiled by the immediate compiler, and so on, as well as all threads shared by the thread.
Chang (Constant Pool): Part of the method area, the Java language does not require constants to be generated only at compile time, the runtime can also put new constants into the constant pool, the string class of The Intern () method is used more than the operation of the constant number of ways to add.
Static zone: Part of the method area that stores the members of the static decoration (static variables or static decorated blocks) or global variables.
Here is the Java in-memory execution flow
:
Java from Basics (iv) Java memory mechanism