One of the algorithms for cleaning phases: Mark-sweep algorithm juejin.cn/post/690861… Background In order to address the shortcomings of the mark-sweep algorithm in garbage collection efficiency, M.L. Insky published a famous paper in 1963, “Lisp language Garbage collector CA Lisp Garbage CoIIector Algorithm Using SeriaI Secondary Storage.

In order to address the shortcomings of the mark-sweep algorithm in garbage collection efficiency, M.L. Insky published a famous paper in 1963, “Lisp language Garbage collector CA Lisp Garbage CoIIector Algorithm Using SeriaI Secondary Storage. The algorithms m.L. Insky described in this paper are known as copying algorithms, which m.L. Insky himself successfully introduced into an implementation of Lisp.

The living memory space is divided into two pieces and only one piece is used each time. During garbage collection, the living objects in the used memory are copied to the unused memory block. After that, all objects in the used memory block are cleared, the roles of the two memory blocks are swapped, and finally garbage collection is completed.

Pointer collision algorithm can be used to store new objects. Advantages: No marking and cleaning process, simple implementation, efficient running after the copy to ensure space continuity, no “fragmentation” problem. Disadvantages: The disadvantages of this algorithm are also obvious, that is, it requires twice the memory space. For GC with a large number of regions, such as G1, replication rather than movement means that the GC needs to maintain object reference relationships between regions, which is not a small amount of memory or time. Special: If there are many live objects in the system, the number of live objects that the replication algorithm needs to copy will be large. Therefore, the survival of the object is very low, (application: such as S0 S1, the day of death). In the new generation, garbage collection for conventional applications can typically reclaim 70 to 90 percent of memory at a time. Recycling is cost-effective. So now commercial virtual machines are using this collection algorithm to recycle the new generation.

It’s an improvement over Mark-Sweep, but there’s a market for both. Each for its own good!