Objects are allocated first in Eden
In most cases, objects are allocated first in the new generation Eden area. When the Eden memory area does not have enough space for allocation, the virtual machine will trigger a Minor GC (New Generation GC). During Minor GC, the virtual machine moves objects in the Eden area to one of the Survivor areas.
##Large objects directly enter the old generation
The so-called large objects refer to Objects that require large amounts of contiguous space. The virtual machine provides an XX:PretenureSizeThreshold parameter, so that objects larger than this value are directly allocated in the old generation.
Long-term surviving objects will enter the old generation
The virtual machine uses the idea of generational collection to manage memory. When recycling memory, it must be able to identify which objects should be placed in the new generation and which should be placed in the new generation. In the old age. In order to achieve this, the virtual machine defines an object age for each object. Each time it still survives after a new generation GC, the object's age is increased by 1 year. When the age reaches a certain level (default is 15), Will be promoted to the old generation. The age limit for the object to be promoted to the old generation can be set by -XX:MaxTenuringThreshold.
The difference between Minor GC and Full GC
New generation GC (Minor GC): refers to the garbage collection action that occurs in the new generation. Because most objects have the characteristics of being born and dying, Minor GC is very Frequent and the recovery speed is relatively fast.
Old generation GC (Major GC / Full GC): refers to the GC that occurs in the old generation. After the occurrence of Major GC, it is often accompanied by at least one Minor GC. The speed of Major GC is generally more than 10 times slower than Minor GC.
The above is the content of Java virtual machine learning - object memory allocation and recycling. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!
Related articles:
Detailed explanation of Java virtual machine
In-depth understanding of Java virtual machine
Java Virtual Machine Learning - Class Loading Mechanism
Java Virtual Machine Learning - Object Access