On Wed, 22 Jun 2022 04:55:39 GMT, Michael Strauß <[email protected]> wrote:

> Fundamentally, the problem does not arise from bindings, but from the fact 
> that `ListPropertyBase` adds a `ListChangeListener` to its wrapped 
> `ObservableList`.

Yes, I would agree.  The cause is the eager setup of listeners on other 
properties, resulting in the target being tied to the lifecycle of the observed 
property.  The listener itself serves no purpose until the `ListProperty` 
itself is observed in some fashion.  A `ListProperty` could be processing 
thousands of "changes" to update its internal state, but if it is not observed 
or called directly, nobody cares.  The end result is that the property cannot 
be garbage collected and is processing every change event, even though 
everything has lost interest in it.

This is basically another case where it is better to only listen (or bind) to 
other targets when absolutely necessary (when the source itself is being 
observed) and to remove the listener (or binding) when no longer observed, 
basically lazy versus eager observation. Lazy observation would completely 
remove the need for using weak references, simplifying the logic and making the 
whole system much easier to reason about.

-------------

PR: https://git.openjdk.org/jfx/pull/689

Reply via email to