The JVM is based on the accessibility analysis algorithm to find the objects that need to be recycled, to determine whether the object's survival status is related to the reference.
Before JDK1.2, this design is very simple: the state of an object is only referenced and not referenced in two different ways.
Such partitioning is not very friendly to garbage collection because there are always some objects that are in the state of the two.
So four new states have been added after 1.2 for finer-grained partitioning of referential relationships:
Strong reference (Strong Reference): This object is most common, such as A a = new A(); this is a typical strong reference, such a strong referential relationship can not be garbage collection. Soft references (Soft Reference): Such references indicate useful but not necessary objects that need to be recycled before garbage collection occurs. Weak references (Weak Reference): This is a reference relationship that is weaker than a soft reference and is a non-mandatory object. When garbage is collected, objects like this are recycled regardless of whether the current memory is sufficient. Virtual reference (Phantom Reference): This is the weakest reference relationship and cannot even get the object by reference, its only function is to be notified when it is recycled.
References in Java