01: /*
02: *
03: *
04: * Copyright 1990-2007 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: package java.lang.ref;
28:
29: /**
30: * This class provides support for weak references. Weak references
31: * are most often used to implement canonicalizing mappings.
32: *
33: * Suppose that the garbage collector determines at a certain
34: * point in time that an object is weakly reachable. At that
35: * time it will atomically clear all the weak references to
36: * that object and all weak references to any other weakly-
37: * reachable objects from which that object is reachable
38: * through a chain of strong and weak references.
39: *
40: * @version 12/19/01 (CLDC 1.1)
41: * @since JDK1.2, CLDC 1.1
42: */
43:
44: /*
45: * Implementation note: It is generally recommended that
46: * you don't subclass the WeakReference class. The garbage
47: * collector treats weak references specially, and the
48: * subclasses of class WeakReference might not be handled
49: * correctly by the garbage collector.
50: */
51:
52: public class WeakReference extends Reference {
53:
54: private int referent_index;
55:
56: /**
57: * Returns this reference object's referent. If this reference object has
58: * been cleared, either by the program or by the garbage collector, then
59: * this method returns <code>null</code>.
60: *
61: * @return The object to which this reference refers, or
62: * <code>null</code> if this reference object has been cleared
63: */
64: public native Object get();
65:
66: /**
67: * Clears this reference object.
68: */
69: public native void clear();
70:
71: /**
72: * Creates a new weak reference that refers to the given object.
73: */
74: public WeakReference(Object referent) {
75: super (referent);
76: initializeWeakReference(referent);
77: }
78:
79: private native void initializeWeakReference(Object referent);
80:
81: private native void finalize();
82: }
|