Java garbage collection -GC

Determining whether the object belongs to Garbage:

  • Determining a reference number of objects
    • Determined by the number of reference objects is determined, whether the recovered, reference number = 0 is treated as waste
    • Each object instance, has a reference counter, referenced +1, -1 complete reference
    • Advantages: high efficiency, small impact of the implementation program
    • Cons: the case of circular references can not be detected, leading to memory leaks
  • Reachability analysis algorithm
    • Determining whether the object referenced by the chain up, to determine whether the object can be recovered
    • GC Root objects can be used as follows:
      •   VM stack objects referenced (local variable table stack frame)
      •   The method of constant reference object region
      •   Method region static property class object reference
      •   Native method of native method stacks of reference objects
      •       Active thread object reference

Garbage collection algorithm:

  1. Mark - sweep algorithm
    • Disadvantages: easily lead to fragmentation
  2. Replication algorithm
    • For low survival rate of cases of Object
    • Solve the fragmentation problem
  3. * Generational collection algorithm

 

Guess you like

Origin www.cnblogs.com/starstarstar/p/11240143.html