A programmer from Shanghai piao after 90 years, only focus on sharing dry goods
Update every weekend, your likes and comments plus attention is a great power of xiaobian, Ollie to ~
JAVA four reference types
After JDK version 1.2, Java expanded the concept of references, dividing them into the following four categories, which gradually decreased in intensity.
Strongly Re-reference (Strongly re-reference)
- The most common in Java is strong references, where an object is assigned to a reference variable that is a strong reference. When an object is referenced by a strongly referenced variable, it is in a reachable state,It can’t be collected by a garbage collection mechanismEven though the object will never be used by the JVM or recycled. So strong references are one of the main causes of Java memory leaks.
Soft Reference
- Soft references are implemented using the SoftReference class. For objects that only have soft references,It is not reclaimed when the system memory is sufficient, and it is reclaimed when the system memory is insufficient. Soft references are usually used in memory-sensitive programs.
Weak Reference
- WeakReference needs to be realized by WeakReference class, which has a shorter lifetime than soft reference. For objects with only WeakReference,Whenever the garbage collection mechanism is running, the object’s memory is reclaimed, regardless of whether the JVM has enough memory.
Phantom Reference
- Virtual references need to be implemented by the PhantomReference class, which cannot be used alone but must be used in conjunction with the reference queue. The main purpose of virtual references isTracks the state of the object being garbage collected
Conclusion: I am not bald goat, a Shanghai drift 90 after the ordinary programmer, unwilling to ordinary, just want to find a rich woman
Thanks for your likes, comments and follows. see you next time
A Shanghai piao 90 after the ordinary programmer, only focus on sharing dry goods
Update every weekend, your likes and comments plus attention is a great power of xiaobian, Ollie to ~