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.
InvalidationListener, Observable
| Modifier and Type | Field and Description |
|---|---|
| private final WeakReference |
| Access | Constructor and Description |
|---|---|
| public | WeakInvalidationListener(InvalidationListener
The original listener that should be notified listener)The constructor of |
| Modifier and Type | Method and Description |
|---|---|
| public void | invalidated(Observable
The observable)Observable that became invalidImplements javafx. This method needs to be provided by an implementation of
|
| public boolean | wasGarbageCollected()
Implements javafx. Returns |
| ref | back to summary |
|---|---|
| private final WeakReference<InvalidationListener> ref | |
| WeakInvalidationListener | back to summary |
|---|---|
| public WeakInvalidationListener(InvalidationListener listener) The constructor of
| |
| invalidated | back to summary |
|---|---|
| public void invalidated(Observable observable) Implements javafx. Doc from javafx. This method needs to be provided by an implementation of
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
| |