Binding.dispose

Johan Vos johan.vos at gluonhq.com
Thu Dec 19 12:27:42 UTC 2024


Hi,

I believe the javadoc in Binding.dispose() is misleading. Before creating
an issue for this, it would be good to know if others have other
interpretation, or suggestions for improvements.

I recently ran into a memory leak that was caused by this binding:

```
someDoubleProperty.bind(Bindings.when(someBooleanProperty).then(cell.layoutYProperty()).otherwise(0));
...
someDoubleProperty.unbind();
```

This flow creates a memoryleak as the NumberBinding created in the then
clause is not using a WeakInvalidationListener, hence it has to be disposed
manually.
However, the javadoc for Binding.dispose() says:
```
 All bindings in our implementation use instances of
WeakInvalidationListener, which means usually a binding does not need to be
disposed.
```

I think this is incorrect and should be fixed.
In general, I believe the javadoc about Binding needs to be revisited.
There are too many occurrences like "in general", "usually", "optional",
which contributes to the idea that bindings are fuzzy logic.

- Johan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/openjfx-dev/attachments/20241219/76b46aa4/attachment.htm>


More information about the openjfx-dev mailing list