Java's JVM memory can be divided into 3 zones: heap, stack (stack), and method area
- Each thread contains a stack that stores only the underlying data types and custom object references (not objects)in the method (not including the object's member variables), and objects are stored in the heap area
- The data in each stack (both the original type and the object reference) is private and the other stacks are inaccessible.
- The stack is divided into 3 parts: the basic type variable area, the execution environment context, the operation instruction area (holds the operation instruction).
- All of the stored objects are object instances, each containing a class information (class information is stored in the method area).
- The JVM has only one heap area (heap) that is shared by all threads , the heap does not hold the base type and object references, only the object itself, and almost all object instances and arrays are allocated in the heap.
- Also called the static zone, like the heap, is shared by all threads. It is used to store data such as class information, constants, static variables, and code compiled by the immediate compiler that have been loaded by the virtual machine.
Portal: https://www.zhihu.com/question/29833675
Understanding stacks, heaps, stacks in Java virtual machines