Detailed explanation of Java garbage collection (GC) mechanism

How to Find Trash to Recycle

  • 1. Reference counting
  • 2. Accessibility Analysis

Three, four reference states

  • 1. Strong citations

  • 2. Soft references

  • 3. Weak references

  • 4. Virtual reference

Enter image description

5. Garbage Collection Algorithms

  • 1. Mark-Sweep algorithm
  • 2. Copying algorithm
  • 3. Mark-Compact algorithm
  • 4. Generational collection algorithm: a large number of objects die and a small number of objects survive (new generation), the replication algorithm is used, and the replication cost is low; the object survival rate is high, and there is no extra space for allocation guarantee (old generation), using mark-cleaning algorithm Or mark-collate algorithms.

6. Garbage collector

Enter image description

1. Serial collector

  • 1. Single-threaded work
  • 2. Adopt the replication algorithm

2. ParNew collector

  • 1. Multi-threaded work 2. Using replication algorithm

3. CMS collector

  • (1). Initial marking, marking the objects that GCRoots can directly associate with, and the time is very short.
  • (2). Concurrent marking, the process of GCRoots Tracing (reachability analysis) is very long.
  • (3) Re-marking, correcting the marking record of the part of the object whose marking is changed due to the continuous operation of the user program during the concurrent marking, which takes a long time.
  • (4). Concurrent clearing and reclaiming memory space takes a long time.

7. G1 collector

Link

Detailed explanation of Java garbage collection (GC) mechanism

Essay Classification - Java Virtual Machine

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324910851&siteId=291194637