Feedback requested for infrastructure for properties that wish to delay registering listeners
Michael Strauß
michaelstrau2 at gmail.com
Mon Feb 6 05:00:06 UTC 2023
I like your proposal in general, since it may result in a performance
improvement in some cases. If we can avoid to eagerly registering
listeners that aren't needed, that's great.
However, it is not an alternative to using weak listeners. Consider
the following test, which is taken from Florian's PR
(https://github.com/openjdk/jfx/pull/689):
@Test
public void testListPropertyLeak2() {
JMemoryBuddy.memoryTest(checker -> {
ObservableList<Object> list = FXCollections.observableArrayList();
ListProperty<Object> listProperty = new SimpleListProperty<>(list);
checker.setAsReferenced(list);
checker.assertCollectable(listProperty);
});
}
This test only passes with your PR because `listProperty` doesn't
register a listener on `list` (that's what you are proposing, after
all).
As soon as you do that, for example by adding the following line, the
test fails:
listProperty.addListener((ListChangeListener<? super Object>) change -> {});
But the test shouldn't ever fail, because the ObservableList that is
wrapped by ListProperty should never keep a strong reference to the
ListProperty, even if the ListProperty is itself observed.
That's a bug in the current implementation, and hiding it by making it
contingent upon the presence of observers doesn't fix the underlying
issue.
On Sun, Feb 5, 2023 at 10:46 AM John Hendrikx <john.hendrikx at gmail.com> wrote:
>
> Any comments on this?
>
> I think having API to make it easier for both JavaFX and users to create
> listeners that can delay registration to their own dependencies. This
> would be an alternative to using weak listeners for these cases.
>
> --John
More information about the openjfx-dev
mailing list