WeakChangeListener can be used if an ObservableValue
should only maintain a weak reference to the listener. This helps to avoid
memory leaks which can occur if observers are not unregistered from observed
objects after use.
WeakChangeListener instances are created by passing in the original
ChangeListener. The WeakChangeListener should then be
registered to listen for changes of the observed object.
Note
You have to keep a reference to the ChangeListener that
was passed in for as long as it is in use, otherwise it will be garbage collected
too soon.
ChangeListener, ObservableValue
| Modifier and Type | Field and Description |
|---|---|
| private final WeakReference |
| Access | Constructor and Description |
|---|---|
| public | WeakChangeListener(ChangeListener<T>
The original listener that should be notified listener)The constructor of |
| Modifier and Type | Method and Description |
|---|---|
| public void | changed(ObservableValue<? extends T>
The observable, T ObservableValue which value changedThe old value oldValue, T The new value newValue)Implements javafx. Called when the value of an |
| public boolean | wasGarbageCollected()
Implements javafx. Returns |
| ref | back to summary |
|---|---|
| private final WeakReference<ChangeListener<T>> ref | |
| WeakChangeListener | back to summary |
|---|---|
| public WeakChangeListener(ChangeListener<T> listener) The constructor of
| |
| changed | back to summary |
|---|---|
| public void changed(ObservableValue<? extends T> observable, T oldValue, T newValue) Implements javafx. Doc from javafx. Called when the value of an In general, it is considered bad practice to modify the observed value in this method.
| |
| wasGarbageCollected | back to summary |
|---|---|
| public boolean wasGarbageCollected() Implements javafx. Doc from javafx. Returns
| |