Java Virtual Machine-garbage collection algorithm, java garbage collection
This article mainly introduces the garbage collection algorithm of Java virtual machine.
I. Overview
Ii. Mark-clear Algorithm
Mark-Sweep. Like the name, the algorithm is divided into two steps:
Disadvantages:
Iii. replication algorithm
The replication algorithm is an optimization of tag clearing. It divides the memory on the heap into two areas of equal size, one is the idle area and the other is the active area. In the running of the program, the actual use is the activity area, that is, 50% of the space is wasted.
Implementation process:
Advantage: After memory is recycled, there will be a large partContinuous.
Disadvantage: 50% of the memory space is stored. GC only Uses idle areas when memory is recycled.
Iv. tagging-Sorting Algorithm
The tag operation is consistent with the "tag-clear" algorithm. Subsequent operations not only clean up objects directly, but move all surviving objects to one end after useless objects are cleared, update the pointer of the referenced object.
Main disadvantage: objects need to be moved on the basis of tag-clearing, and the cost is relatively high. The advantage is that memory fragments are not generated.
V. Generational Collection Algorithms
Divide java heap into the new generation and old generation: