RFR: 8293444: Creating ScrollPane with same content component causes memory leak [v3]
Florian Kirmaier
fkirmaier at openjdk.org
Thu Sep 29 08:05:29 UTC 2022
On Wed, 28 Sep 2022 18:02:53 GMT, Andy Goryachev <angorya at openjdk.org> wrote:
>> Using Weak*Listeners eliminates the memory leak.
>
> Andy Goryachev has updated the pull request incrementally with one additional commit since the last revision:
>
> 8293444: review comments
Of course, you can keep it this way.
The point of JMemoryBuddy.memoryTest is, that the user doesn't have to fiddle around with WeakReferences.
For the record, your test might look like this (not tested):
@Test
public void testScrollPaneObjLeakWhenUsedSameContent() {
JMemoryBuddy.memoryTest(() -> {
BorderPane bp = new BorderPane();
Stage stage = new Stage();
stage.setScene(new Scene(bp));
stage.show();
Label content = new Label("content");
ScrollPane sp1 = new ScrollPane(content);
bp.setCenter(sp1);
Toolkit.getToolkit().firePulse();
ScrollPane sp2 = new ScrollPane(content);
bp.setCenter(sp2);
Toolkit.getToolkit().firePulse();
bp.setCenter(null);
Toolkit.getToolkit().firePulse();
// When the label is still referenced, then only one ScrollPane should stay which is its parent
checker.setAsReferenced(label)
checker.assertCollectable(sp1)
checker.assertNotCollectable(sp2)
});
}
@Test
public void testScrollPaneObjLeakWhenUsedSameContent() {
JMemoryBuddy.memoryTest(() -> {
BorderPane bp = new BorderPane();
Stage stage = new Stage();
stage.setScene(new Scene(bp));
stage.show();
Label content = new Label("content");
ScrollPane sp1 = new ScrollPane(content);
bp.setCenter(sp1);
Toolkit.getToolkit().firePulse();
ScrollPane sp2 = new ScrollPane(content);
bp.setCenter(sp2);
Toolkit.getToolkit().firePulse();
bp.setCenter(null);
Toolkit.getToolkit().firePulse();
// IF our label is gone, both scrollpanes shold be collectable
checker.assertCollectable(sp1)
checker.assertCollectable(sp2)
});
}
I think only the first test is the important one.
-------------
PR: https://git.openjdk.org/jfx/pull/900
More information about the openjfx-dev
mailing list