Class WeakReference
public class WeakReference
{
// Constructors
public WeakReference(Object referent);
// Methods
public void finalize();
public Object getReferent();
public void setReferent(Object object);
}
This class implements a weak reference to an object. A weak reference tracks an object without preventing it from being garbage-collected.
public WeakReference(Object referent);
Constructs a weak reference to a specified object.
Parameter | Description |
referent
| The object to track.
|
public void finalize();
Finalizes the weak reference instance. The referent is no longer tracked.
Return Value:
No return value.
public Object getReferent();
Retrieves the current object being tracked.
Return Value:
Returns the object being tracked; returns null if the object was collected.
public void setReferent(Object object);
Sets the current object being tracked.
Return Value:
No return value.
Parameter | Description |
object
| The object being tracked, or null if the object was collected.
|