The basic data type in Java is stored in the stack, while the composite data type uses a reference model, which is stored in the stack, while the object is stored in the heap. That is, the so-called Java divides the internal memory into two: one is a stack memory, one is a stack of memory.
Some of the basic types of variables defined in the function are allocated in the stack memory of the function.
When a variable is defined in a block, Java assigns memory space for this variable in the stack. When the variable is exceeded, Java automatically releases the memory space allocated to the variable, the memory space can be immediately Another use him.
Pile of memory is stored by the objects and arrays created by NEW.
The memory allocated in the heap is managed by the automatic garbage collector of the Java virtual machine.
After a group or object is generated in the heap, you can define a special variable in the stack, allowing the value of this variable in the stack equal to the array or the first address in the stack memory, and this variable in the stack has become The reference variable of array or object.
The reference variable is equivalent to a name that is from the array or object, and the array or object in the stack can be accessed using the reference variable in the stack in the program.
Of course, it is divided into two types in the stack: one of the stacks is an object and array created by New, and another pile is used to store the loaded class information, and the Static variable is stored in this class information. .