1 /* 2 * @(#)WeakReference.java 1.18 03/12/19 3 * 4 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 5 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. 6 */ 7 8 package java.lang.ref; 9 10 11 /** 12 * Weak reference objects, which do not prevent their referents from being 13 * made finalizable, finalized, and then reclaimed. Weak references are most 14 * often used to implement canonicalizing mappings. 15 * 16 * <p> Suppose that the garbage collector determines at a certain point in time 17 * that an object is <a HREF="package-summary.html#reachability">weakly 18 * reachable</a>. At that time it will atomically clear all weak references to 19 * that object and all weak references to any other weakly-reachable objects 20 * from which that object is reachable through a chain of strong and soft 21 * references. At the same time it will declare all of the formerly 22 * weakly-reachable objects to be finalizable. At the same time or at some 23 * later time it will enqueue those newly-cleared weak references that are 24 * registered with reference queues. 25 * 26 * @version 1.18, 12/19/03 27 * @author Mark Reinhold 28 * @since 1.2 29 */ 30 31 public class WeakReference<T> extends Reference<T> { 32 33 /** 34 * Creates a new weak reference that refers to the given object. The new 35 * reference is not registered with any queue. 36 * 37 * @param referent object the new weak reference will refer to 38 */ 39 public WeakReference(T referent) { 40 super(referent); 41 } 42 43 /** 44 * Creates a new weak reference that refers to the given object and is 45 * registered with the given queue. 46 * 47 * @param referent object the new weak reference will refer to 48 * @param q the queue with which the reference is to be registered, 49 * or <tt>null</tt> if registration is not required 50 */ 51 public WeakReference(T referent, ReferenceQueue<? super T> q) { 52 super(referent, q); 53 } 54 55 } 56