title: Understanding Phantom reference vs weak reference with respect to Reference queue
body: <p>As per the link <a href="https://weblogs.java.net/blog/enicholas/archive/2006/05/understanding_w.html" rel="nofollow noreferrer">https://weblogs.java.net/blog/enicholas/archive/2006/05/understanding_w.html</a>, <strong>PhantomReferences</strong> are enqueued only when the object is physically removed from memory and <strong>WeakReferences</strong> are enqueued before finalization or garbage collection has actually happened.</p>
  <blockquote>
  <p>The difference is in exactly when the enqueuing happens.
  WeakReferences are enqueued as soon as the object to which they point
  becomes weakly reachable. This is before finalization or garbage
  collection has actually happened; in theory the object could even be
  &quot;resurrected&quot; by an unorthodox finalize() method, but the
  WeakReference would remain dead. PhantomReferences are enqueued only
  when the object is physically removed from memory, and the get()
  method always returns null specifically to prevent you from being able
  to &quot;resurrect&quot; an almost-dead object.</p>
  </blockquote>
  <p>whereas as per <a href="http://www.ibm.com/developerworks/library/j-refs/" rel="nofollow noreferrer">http://www.ibm.com/developerworks/library/j-refs/</a>, <strong>PhantomReference</strong> is added to its <strong>ReferenceQueue</strong> before the heap object is freed and  and <strong>WeakReferences</strong> are added to its ReferenceQueue after finalization or garbage collection.</p>
  <blockquote>
  <p>Unlike soft and weak references, the PhantomReference is added to its
  ReferenceQueue before the heap object is freed. (Remember, all
  PhantomReference objects must be created with an associated
  ReferenceQueue.) This allows for action to be taken before the heap
  object is reclaimed.</p>
  <p>When the heap object's finalize() method is run and its memory freed,
  the WeakReference object is added to its ReferenceQueue, if it exists.</p>
  </blockquote>
  <p>I am confused. Which one is correct?</p>
  <p>Basically i want to know the difference between weak and phantom reference with respect to Reference Queue?</p>