A detailed description of reference types in Java

  • 2020-04-01 02:19:22
  • OfStack

The & # 8226; Strong reference (FinalReference), in Java, a bit like a C++ pointer, through the reference, can be used to manipulate objects in the heap. Strong references have the following characteristics:
1. Strong reference can directly access the target object;
2. The object pointed to by the strong reference will not be recovered by the system during the task;
3. Strong references can cause memory leaks.
The & # 8226; A SoftReference object that is cleared by the garbage collector in response to a memory need. An object that holds a software reference will not be recovered quickly by the JVM. As long as there is enough memory, the software reference may live in memory for a long time.
The & # 8226; WeakReference, WeakReference is a relatively WeakReference type, in the system GC, as long as the WeakReference is found, regardless of whether the system heap memory is enough, will object recovery;
The & # 8226; PhantomReference, a virtual reference is the weakest of all references. An object that holds a virtual reference is almost the same as an object that has no reference and can be collected by the garbage collector at any time.


Related articles: