RFR: 8277848 Binding and Unbinding to List leads to memory leak [v4]
Michael Strauß
mstrauss at openjdk.org
Wed Jun 22 04:58:56 UTC 2022
On Tue, 11 Jan 2022 19:04:56 GMT, Florian Kirmaier <fkirmaier at openjdk.org> wrote:
>> Making the initial listener of the ListProperty weak fixes the problem.
>> The same is fixed for Set and Map.
>> Due to a smart implementation, this is done without any performance drawback.
>> (The trick is to have an object, which is both the WeakReference and the Changelistener)
>> By implying the same trick to the InvalidationListener, this should even improve the performance of the collection properties.
>
> Florian Kirmaier has updated the pull request incrementally with one additional commit since the last revision:
>
> JDK-8277848
> Added the 3 requests whitespaces
Fundamentally, the problem does not arise from bindings, but from the fact that `ListPropertyBase` adds a `ListChangeListener` to its wrapped `ObservableList`.
Since the added `ListChangeListener` is a capturing lambda, the `ListPropertyBase` is now tied to the lifetime of the wrapped `ObservableList`. This failing test illustrates the problem:
JMemoryBuddy.memoryTest(checker -> {
ObservableList<Object> list = FXCollections.observableArrayList();
ListProperty<Object> listProperty = new SimpleListProperty<>(list);
checker.setAsReferenced(list);
checker.assertCollectable(listProperty); // --> AssertionError: listProperty not collected
});
This behavior may or may not be a bug. I'm inclined to think that it is, because I would be astonished to learn that an object contained in a `Property<T>` would hold a strong reference to the property instance itself.
-------------
PR: https://git.openjdk.org/jfx/pull/689
More information about the openjfx-dev
mailing list