The difference between SoftReference and WeakReference

  • SoftReference is a soft reference, second only to strong reference, and is reclaimed when OOM is about to occur after garbage collector GC if there is not enough memory.

  • WeakReference is a weak reference, second only to soft reference. When the JVM recycles garbage, objects associated with weak references will be recycled regardless of whether there is sufficient memory.