JVM's garbage collection algorithm

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/GoSaint/article/details/90116398

Mark - sweep algorithm

Clear labeling algorithm is divided into two stages, marking phase and cleanup phase, the two phases is relatively inefficient, and will produce memory fragmentation after collection, not for the large object allocation memory space.
As shown below:Here Insert Picture Description

Replication algorithm

Replication algorithm solves the problem of memory fragmentation, but the attendant is the memory into two. The principle is: the memory into two, half of them each time, when the need to be recovered, say death to clean up the object, and then move to the other side of live objects, thus avoiding memory fragmentation.
Here Insert Picture Description
Of course, in today's business virtual machine point of view, it does not need the memory into two, so the price is too big friends. 98% of the objects are born toward evening death, HotSpot memory into the new generation and the old era. Cenozoic is divided into Eden, from Suvivor, to Survivor and survivor Eden default size is 8: 1 is the new generation of recycling 90% of the entire new generation of memory.
Here Insert Picture Description

Mark - Collation Algorithm

Tags to organize algorithm is surviving to the end of the moving object, and then clear the memory beyond the boundary. Mainly for old's collection.
Here Insert Picture Description

Generational collection algorithm

Copy the new generation algorithm using a small amount of objects can be copied to a survivor of them. Year old mark finishing method used to collect.

Guess you like

Origin blog.csdn.net/GoSaint/article/details/90116398