First, strong references. No matter when, the garbage collector does not recycle him, and if memory is low, it throws an Oom exception and does not reclaim the strongly referenced object.
Second, soft reference. Through class SoftReference. It tells the garbage collector that it will be reclaimed by the collector when it is out of memory, and if the memory is still insufficient after releasing these objects, Oom will be thrown. {Suitable for cache} strong.
Third, weak references. WeakReference. As soon as the garbage collection is started, objects that are weakly referenced are recycled. The effect is the existence of the coupling between the objects brought by the strong reference. The most common use is in the collection class.
Four, virtual reference. A virtual reference cannot be used to get an object instance, and the sole purpose of setting a virtual reference for an object is to receive a system notification when the object is garbage collected.
Reference types in Java