The basic data type is directly allocated in the stack space.
Method form parameters are directly allocated in the stack space. After the method call is completed, the stack space is reclaimed.
To reference the data type, you must use new to create a class variable that allocates an address space in the stack space and objects in the heap space.
Method reference parameters: Allocate an address space in the stack space and point to the object area of the heap space. After the method is called, it is reclaimed from the stack space.
When the local variable is new, space is allocated in the stack space and heap space. When the lifecycle of the local variable ends, the stack space is immediately recycled, and the heap space area is waiting for GC to be recycled.
The literal parameter passed in when the method is called. It is first allocated in the stack space, and then allocated from the stack space after the method is called.
String constants are allocated in the data area.
This is allocated in the heap space.
The array allocates both the array name in the stack space and the actual size of the array in the heap space.
In Java, memory management is divided into Stack-stack, heap-heap, data segment-data segment, and code segment-code segment.
First, identify what is stored in each area.
STACK: It can be translated into a stack area to store some basic data types, command code, constants, and object reference addresses.
The basic data type is the most basic four types and eight types. As mentioned in the previous blog.
Command code is a number of functions and methods.
Constants and object reference addresses can be understood as Defined variables. But only the reference address. The new address is stored in heap, that is, heap memory.
Heap: stores object instances, that is, all new items in the Code are put here.
Data Segment: data segment, which stores static constants and string constants.
Code segment: A code segment that stores the code.