simply talk about references (
excerpt from Java Virtual Machine Second Edition )
Attribution: Wander
one or four types of references
After JDK 1.2, Java extends the concept of references into strong references (strong Reference), soft references (Soft Reference), weak references (Weak Reference), virtual references (Phantom Reference) 4 species, these 4 kinds of reference strength gradually weakened.
Ii. Introduction and timing of recycling
1. Strong citation >>> refers to the general existence of code in the program, similar to "Object Obj=new object ()" Such a reference, as long as the strong reference also exists, the garbage collector will never reclaim the referenced object.
2. Soft reference >>> is used to describe objects that are useful but not necessary. For objects associated with soft references, these objects are then listed in the collection scope for a second collection before the system is about to occur with a memory overflow exception. If this collection does not have enough memory, a memory overflow exception will be thrown. After JDK 1.2, the SoftReference class was provided to implement soft references.
3. Weak citation >>> is also used to describe a non-required object, but its strength is weaker than soft reference, and the object associated with the weak reference only survives until the next garbage collection occurs. When the garbage collector is working, the objects associated with a weak reference are reclaimed regardless of whether the current memory is sufficient. After JDK 1.2, the WeakReference class was provided to implement weak references. (Threadlocal uses a weak reference, can be self-study)
4. Virtual References >>> A virtual reference, also known as a phantom reference or phantom Reference, is the weakest reference relationship. Whether an object has a virtual reference exists, does not affect its lifetime at all, and cannot obtain an object instance through a virtual reference. The only purpose of setting a virtual reference association for an object is to be able to receive a system notification when the object is reclaimed by the collector. After JDK 1.2, the Phantomreference class is provided to implement the virtual reference.
Java Talk about references (strong references (strong Reference), soft references (Soft Reference), weak references (Weak Reference), virtual references (Phantom Reference))