01: /*=============================================================================
02: * Copyright Texas Instruments 2003. All Rights Reserved.
03: *
04: * This program is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This program is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: *
18: * $ProjectHeader: OSCRIPT 0.155 Fri, 20 Dec 2002 18:34:22 -0800 rclark $
19: */
20:
21: package oscript.data;
22:
23: import oscript.exceptions.*;
24:
25: /**
26: * A weak reference to an object will not prevent the object from being
27: * garbage collected. Before the referent is GC'd, the weak reference
28: * is a proxy for the referent, but once GC'd the weak reference behaves
29: * as <code>null</code>.
30: * <p>
31: * NOTES:
32: * <ul>
33: * <li> passing a weak reference as an argument to java code will cause
34: * the referent itself to be passed to the java method/constructor. If
35: * the java code holds a reference to the referent, this can prevent it
36: * from being GC'd
37: * <li> holding a reference to a member of the referent, even if accessed
38: * through the weak reference, will prevent the referent from being GC'd
39: * </ul>
40: *
41: * @author Rob Clark (rob@ti.com)
42: * @version 1.44
43: */
44: public class WeakReference extends AbstractReference {
45: private java.lang.ref.Reference ref;
46:
47: /*=======================================================================*/
48: /**
49: * Class Constructor.
50: */
51: public WeakReference(Value val) {
52: super ();
53:
54: ref = new java.lang.ref.WeakReference(val);
55: }
56:
57: /*=======================================================================*/
58: /**
59: * Get the referent
60: *
61: * @return the value this reference refers to
62: */
63: protected Value get() {
64: Value val = (Value) (ref.get());
65: if (val == null)
66: return NULL;
67: return val;
68: }
69: }
70:
71: /*
72: * Local Variables:
73: * tab-width: 2
74: * indent-tabs-mode: nil
75: * mode: java
76: * c-indentation-style: java
77: * c-basic-offset: 2
78: * eval: (c-set-offset 'substatement-open '0)
79: * eval: (c-set-offset 'case-label '+)
80: * eval: (c-set-offset 'inclass '+)
81: * eval: (c-set-offset 'inline-open '0)
82: * End:
83: */
|