1. /*
  2. * @(#)PhantomReference.java 1.15 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.lang.ref;
  8. /**
  9. * Phantom reference objects, which are enqueued after the collector
  10. * determines that their referents may otherwise be reclaimed. Phantom
  11. * references are most often used for scheduling pre-mortem cleanup actions in
  12. * a more flexible way than is possible with the Java finalization mechanism.
  13. *
  14. * <p> If the garbage collector determines at a certain point in time that the
  15. * referent of a phantom reference is <a
  16. * href="package-summary.html#reachability">phantom reachable</a>, then at that
  17. * time or at some later time it will enqueue the reference.
  18. *
  19. * <p> In order to ensure that a reclaimable object remains so, the referent of
  20. * a phantom reference may not be retrieved: The <code>get</code> method of a
  21. * phantom reference always returns <code>null</code>.
  22. *
  23. * <p> Unlike soft and weak references, phantom references are not
  24. * automatically cleared by the garbage collector as they are enqueued. An
  25. * object that is reachable via phantom references will remain so until all
  26. * such references are cleared or themselves become unreachable.
  27. *
  28. * @version 1.15, 01/23/03
  29. * @author Mark Reinhold
  30. * @since 1.2
  31. */
  32. public class PhantomReference extends Reference {
  33. /**
  34. * Returns this reference object's referent. Because the referent of a
  35. * phantom reference is always inaccessible, this method always returns
  36. * <code>null</code>.
  37. *
  38. * @return <code>null</code>
  39. */
  40. public Object get() {
  41. return null;
  42. }
  43. /**
  44. * Creates a new phantom reference that refers to the given object and
  45. * is registered with the given queue.
  46. *
  47. * @param referent the object the new phantom reference will refer to
  48. * @param q queue the phantom reference is registered with
  49. * @throws NullPointerException If the <code>queue</code> argument
  50. * is <code>null</code>
  51. */
  52. public PhantomReference(Object referent, ReferenceQueue q) {
  53. super(referent, q);
  54. }
  55. }