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