What are the garbage collection algorithms of JVM?

Garbage collection algorithm

Mark-sweep algorithm

First mark the objects that need to be recycled, and collect all marked objects uniformly after the marking is completed. The marking process is inefficient, and a large number of discontinuous fragments will be generated after the marking is removed.Insert picture description here

Copy algorithm

In order to solve the problem of efficiency, the replication algorithm uses the memory to be divided into blocks of the same size, and one block is used each time. When this block of memory is used up, the surviving objects are copied to another block of memory, and then the The used space is cleaned up at one time, so the processing method is to reclaim half of the memory interval.Insert picture description here

Mark-up algorithm

A marking algorithm designed according to the characteristics of the old age. The marking process is the same as the mark-sweep algorithm, but the subsequent steps are not to directly reclaim the recyclable objects, but to move the surviving objects to one end, and then directly clean up the memory outside the boundary .Insert picture description here

Generational collection algorithm

The memory is divided into extremely fast according to the different life cycles of the objects, and the appropriate garbage collection algorithm is selected according to the characteristics of each age. In the new generation, a large number of objects will die each time they are collected. You can choose the replication algorithm and pay half of the memory space to achieve high-frequency conversion of the object life cycle. For objects in the old age, the probability of survival is generally higher, and their extra space will gradually decrease over time. At this time, you can choose the mark-sweep or mark-sort algorithm for garbage collection.

Article reference from: https://www.cnblogs.com/qianguyihao/p/4744233.html

Guess you like

Origin blog.csdn.net/Nerver_77/article/details/108736942