Simple understanding of java memory model

1. The Java memory model consists of heap and stack.

 

2. Some basic type variables and object reference variables defined in the function are allocated in the stack memory of the function.

 

3. When a variable is defined in a code block, Java allocates memory space for the variable in the stack. When the scope of the variable is exceeded, Java will automatically release the memory space allocated for the variable, which can be immediately used for other purposes.

 

4. Heap memory is used to store objects and arrays created by new.

 

5. The heap memory is automatically managed by the garbage collector.

 

6. For the objects and data generated in the heap, you can define a special variable in the stack, and let the value of this variable point to the first address of the object or array in the heap, then this variable becomes the reference variable of the object or array.

 

7. The data in the stack can be shared.

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326666312&siteId=291194637