I. JAVA runtime, the memory area is mainly divided into five parts: method area, heap, virtual machine stack, local method stack, program counter, as shown in the figure:

Heap: an area of memory shared by threads that holds object instances. The Java heap is also the main area managed by the garbage collector. The heap can be divided into the new generation and the old generation, and the new generation can be divided into one Eden zone and two Survivor zones (From Survivor and To Survivor). The newly created object is in Eden. After a Minor GC, the surviving object is moved to the From Survivor zone. The second Minor GC is performed in Eden. Objects From Survivor and objects From Eden are moved To To Survivor, and so on. When the object is copied 16 times, it is sent to the old age.

-Leonard: Well, if you have a Minor Major, you can clean up the entire heap.Copy the code

3. Virtual stack: an area of data that is private to the thread and created at the same time as the thread. The total number is associated with the thread and represents the memory model of Java method execution. Each method execution creates a stack frame to store the method’s variator, operand stack, dynamically linked method, return value, return address, and so on. Each method from the end of the call is a frame in and out of the virtual machine stack process.

4. Local method stack: a data area that is private to the thread and serves the Native methods used by the VIRTUAL machine

5. Program counter: a data area that is private to the thread. It is a small piece of memory space and mainly represents the bytecode line number indicator executed by the current thread. When the bytecode interpreter works, it selects the next bytecode instruction to be executed by changing the value of this counter. Branch, loop, jump, exception handling, thread recovery and other basic functions need to be completed by this counter.