• Strong references: References such as “Object obj=new Object ()” are common in program code. As long as strong references exist, the garbage collector will never reclaim the referenced Object instance.
  • Soft references are used to describe objects that are useful but not necessary. For objects associated with soft references, the object instances are listed in the collection scope for a second collection before the system is about to run out of memory. An out-of-memory exception is thrown if there is not enough memory for this collection. After JDK 1.2, a SoftReference class was provided to implement soft references
  • Weak references: Also used to describe non-essential objects, but weaker than soft references, the object instances associated with weak references only survive until the next garbage collection occurs. When the garbage collector works, object instances associated only with weak references are reclaimed, regardless of whether there is currently sufficient memory. After JDK 1.2, WeakReference classes were provided to implement weak references.
  • Virtual reference: Also known as ghost reference or phantom reference, this is the weakest type of reference relationship. The existence of a virtual reference does not affect the lifetime of an object instance, nor can an object instance be obtained by virtual reference. The only purpose of setting a virtual reference association for an object is to receive a system notification when the object instance is reclaimed by the collector. After JDK 1.2, the PhantomReference class was provided to implement virtual references.