A strong reference is a reference to an object that can't be garbage collected as long as it's referenced:
Emoployee employee = new Employee();
A soft reference stick around for some time and is usually removed when the memory is low. It's usually used for caching.
SoftReference softRef = new SoftReference(myObject);
softRef.get() returns an object as long as it is in memory.
A weak reference is weaker than a soft reference and is discarded at the next garbage collection cycle:
WeakReference weakRef = new WeakReference(myObject);
weakRef.get() returns an object as long as it is in memory.
A phantom reference always return null and is used to keep track of when an object is removed from the memory before being garbage collected, because it's only enqueud at that point and not before the finalization, like in the previous cases. This is rarely used, but it might be useful if we want to know when a big image has been completely discarded.
Copyright © 2013 Welcome to the website of Davis Fiore. All Rights Reserved.