jaroslav@601: /* jaroslav@601: * Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved. jaroslav@601: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jaroslav@601: * jaroslav@601: * This code is free software; you can redistribute it and/or modify it jaroslav@601: * under the terms of the GNU General Public License version 2 only, as jaroslav@601: * published by the Free Software Foundation. Oracle designates this jaroslav@601: * particular file as subject to the "Classpath" exception as provided jaroslav@601: * by Oracle in the LICENSE file that accompanied this code. jaroslav@601: * jaroslav@601: * This code is distributed in the hope that it will be useful, but WITHOUT jaroslav@601: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jaroslav@601: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jaroslav@601: * version 2 for more details (a copy is included in the LICENSE file that jaroslav@601: * accompanied this code). jaroslav@601: * jaroslav@601: * You should have received a copy of the GNU General Public License version jaroslav@601: * 2 along with this work; if not, write to the Free Software Foundation, jaroslav@601: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jaroslav@601: * jaroslav@601: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jaroslav@601: * or visit www.oracle.com if you need additional information or have any jaroslav@601: * questions. jaroslav@601: */ jaroslav@601: jaroslav@601: package java.lang.ref; jaroslav@601: jaroslav@601: jaroslav@601: /** jaroslav@601: * Phantom reference objects, which are enqueued after the collector jaroslav@601: * determines that their referents may otherwise be reclaimed. Phantom jaroslav@601: * references are most often used for scheduling pre-mortem cleanup actions in jaroslav@601: * a more flexible way than is possible with the Java finalization mechanism. jaroslav@601: * jaroslav@601: *

If the garbage collector determines at a certain point in time that the jaroslav@601: * referent of a phantom reference is phantom reachable, then at that jaroslav@601: * time or at some later time it will enqueue the reference. jaroslav@601: * jaroslav@601: *

In order to ensure that a reclaimable object remains so, the referent of jaroslav@601: * a phantom reference may not be retrieved: The get method of a jaroslav@601: * phantom reference always returns null. jaroslav@601: * jaroslav@601: *

Unlike soft and weak references, phantom references are not jaroslav@601: * automatically cleared by the garbage collector as they are enqueued. An jaroslav@601: * object that is reachable via phantom references will remain so until all jaroslav@601: * such references are cleared or themselves become unreachable. jaroslav@601: * jaroslav@601: * @author Mark Reinhold jaroslav@601: * @since 1.2 jaroslav@601: */ jaroslav@601: jaroslav@601: public class PhantomReference extends Reference { jaroslav@601: jaroslav@601: /** jaroslav@601: * Returns this reference object's referent. Because the referent of a jaroslav@601: * phantom reference is always inaccessible, this method always returns jaroslav@601: * null. jaroslav@601: * jaroslav@601: * @return null jaroslav@601: */ jaroslav@601: public T get() { jaroslav@601: return null; jaroslav@601: } jaroslav@601: jaroslav@601: /** jaroslav@601: * Creates a new phantom reference that refers to the given object and jaroslav@601: * is registered with the given queue. jaroslav@601: * jaroslav@601: *

It is possible to create a phantom reference with a null jaroslav@601: * queue, but such a reference is completely useless: Its get jaroslav@601: * method will always return null and, since it does not have a queue, it jaroslav@601: * will never be enqueued. jaroslav@601: * jaroslav@601: * @param referent the object the new phantom reference will refer to jaroslav@601: * @param q the queue with which the reference is to be registered, jaroslav@601: * or null if registration is not required jaroslav@601: */ jaroslav@601: public PhantomReference(T referent, ReferenceQueue q) { jaroslav@601: super(referent, q); jaroslav@601: } jaroslav@601: jaroslav@601: }