01: /*
02: * @(#)PhantomReference.java 1.19 06/10/10
03: *
04: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: *
26: */
27:
28: package java.lang.ref;
29:
30: /**
31: * Phantom reference objects, which are enqueued after the collector
32: * determines that their referents may otherwise be reclaimed. Phantom
33: * references are most often used for scheduling pre-mortem cleanup actions in
34: * a more flexible way than is possible with the Java finalization mechanism.
35: *
36: * <p> If the garbage collector determines at a certain point in time that the
37: * referent of a phantom reference is <a
38: * href="package-summary.html#reachability">phantom reachable</a>, then at that
39: * time or at some later time it will enqueue the reference.
40: *
41: * <p> In order to ensure that a reclaimable object remains so, the referent of
42: * a phantom reference may not be retrieved: The <code>get</code> method of a
43: * phantom reference always returns <code>null</code>.
44: *
45: * <p> Unlike soft and weak references, phantom references are not
46: * automatically cleared by the garbage collector as they are enqueued. An
47: * object that is reachable via phantom references will remain so until all
48: * such references are cleared or themselves become unreachable.
49: *
50: * @version 1.12, 02/02/00
51: * @author Mark Reinhold
52: * @since 1.2
53: */
54:
55: public class PhantomReference extends Reference {
56:
57: /**
58: * Returns this reference object's referent. Because the referent of a
59: * phantom reference is always inaccessible, this method always returns
60: * <code>null</code>.
61: *
62: * @return <code>null</code>
63: */
64: public Object get() {
65: return null;
66: }
67:
68: /**
69: * Creates a new phantom reference that refers to the given object and
70: * is registered with the given queue.
71: *
72: * @param referent the object the new phantom reference will refer to
73: * @param q queue the phantom reference is registered with
74: * @throws NullPointerException If the <code>queue</code> argument
75: * is <code>null</code>
76: */
77: public PhantomReference(Object referent, ReferenceQueue q) {
78: super(referent, q);
79: }
80:
81: }
|