Top Description Fields Constructors Methods
javafx.beans

public final Class WeakInvalidationListener

extends Object
implements InvalidationListener, WeakListener
Class Inheritance
All Implemented Interfaces
javafx.beans.WeakListener, javafx.beans.InvalidationListener
Imports
java.lang.ref.WeakReference

A WeakInvalidationListener can be used if an Observable should only maintain a weak reference to the listener. This helps to avoid memory leaks that can occur if observers are not unregistered from observed objects after use.

A WeakInvalidationListener is created by passing in the original InvalidationListener. The WeakInvalidationListener should then be registered to listen for changes of the observed object.

Note

You have to keep a reference to the InvalidationListener that was passed in as long as it is in use, otherwise it can be garbage collected too soon.

Since
JavaFX 2.0
See Also
InvalidationListener, Observable

Field Summary

Modifier and TypeField and Description
private final WeakReference<InvalidationListener>

Constructor Summary

AccessConstructor and Description
public
WeakInvalidationListener(InvalidationListener
The original listener that should be notified
listener
)

The constructor of WeakInvalidationListener.

Method Summary

Modifier and TypeMethod and Description
public void
invalidated(Observable observable)

Implements javafx.beans.InvalidationListener.invalidated.

This method needs to be provided by an implementation of InvalidationListener.

public boolean
wasGarbageCollected()

Implements javafx.beans.WeakListener.wasGarbageCollected.

Returns true if the linked listener was garbage-collected.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

refback to summary
private final WeakReference<InvalidationListener> ref

Constructor Detail

WeakInvalidationListenerback to summary
public WeakInvalidationListener(InvalidationListener listener)

The constructor of WeakInvalidationListener.

Parameters
listener:InvalidationListener

The original listener that should be notified

Method Detail

invalidatedback to summary
public void invalidated(Observable observable)

Implements javafx.beans.InvalidationListener.invalidated.

Doc from javafx.beans.InvalidationListener.invalidated.

This method needs to be provided by an implementation of InvalidationListener. It is called if an Observable becomes invalid.

In general, it is considered bad practice to modify the observed value in this method.

Annotations
@Override
wasGarbageCollectedback to summary
public boolean wasGarbageCollected()

Implements javafx.beans.WeakListener.wasGarbageCollected.

Doc from javafx.beans.WeakListener.wasGarbageCollected.

Returns true if the linked listener was garbage-collected. In this case, the listener can be removed from the observable.

Annotations
@Override