Learning - garbage collection algorithm

Garbage collection algorithm

1, mark - sweep algorithm
first mark all objects need to be recovered, after the completion of uniform recycling mark out all the objects are marked. Disadvantages:

  • Efficiency, marking and clearance process efficiency is not high;
  • It will produce a large number of discrete memory fragmentation mark after clearing;

2, the copy algorithm
available memory capacity is divided by two equal in size, uses only one of them. When this piece of memory runs out, the copy will also survive object to another one above, then memory space has been used once and then clean out. Disadvantages:

  • The memory is reduced to half the original, continuous replication of long-lived objects cause a decrease in efficiency.

3, Mark - compression algorithm
tagging process is still the "mark - sweep" algorithm the same, but the subsequent steps are not directly recycled objects to clean up, but to all surviving objects are moved to the end, then clean out directly outside the boundaries of the end RAM.

4, generational collection algorithm
the Java heap into the new generation and the old year , so it can use the most appropriate collection method based on the characteristics of each era . In the new generation, each time garbage collection when there are a large number of objects found dead, only a few survive, then copy the selection algorithm, only need to pay the cost of reproduction of a small amount of live objects to complete the collection. The old era because of the high survival rate of the object, there is no extra space is allocated to its guarantee, you must use the "mark - clean-up" or "mark - finishing" algorithm to recover.

Guess you like

Origin www.cnblogs.com/zd-blogs/p/12015844.html