-
Bug
-
Resolution: Fixed
-
P4
-
jfx14
Initially detected/reported against selectionModel of ChoiceBox, similar issue for other controls with their respective selection/focusModels (for details, see comment below).
Following failing test case for ChoiceBox. Reason seems to be that ChoiceBoxSelectionModel registers strong listeners to both itemsProperty and the content of the items. Replacing both with weakListeners lets the test pass.
other controls with a selectionModel might have a similar issue
Failing test (as usual, test for leak c&p'ed from available tests ... ):
private WeakReference<SingleSelectionModel<?>> weakSmRef;
/**
* Memory leak on replacing selectionModel.
*/
@Test
public void testReplaceSelectionModelMemory() {
weakSmRef = new WeakReference<>(box.getSelectionModel());
SingleSelectionModel<String> replacingSm = ChoiceBoxShim.get_ChoiceBoxSelectionModel(box);
box.setSelectionModel(replacingSm);
attemptGC(10);
assertNull("selectionModel must be gc'ed", weakSmRef.get());
}
private void attemptGC(int n) {
// Attempt gc n times
for (int i = 0; i < n; i++) {
System.gc();
System.runFinalization();
if (weakSmRef.get() == null) {
break;
}
try {
Thread.sleep(500);
} catch (InterruptedException e) {
System.err.println("InterruptedException occurred during Thread.sleep()");
}
}
}
Following failing test case for ChoiceBox. Reason seems to be that ChoiceBoxSelectionModel registers strong listeners to both itemsProperty and the content of the items. Replacing both with weakListeners lets the test pass.
other controls with a selectionModel might have a similar issue
Failing test (as usual, test for leak c&p'ed from available tests ... ):
private WeakReference<SingleSelectionModel<?>> weakSmRef;
/**
* Memory leak on replacing selectionModel.
*/
@Test
public void testReplaceSelectionModelMemory() {
weakSmRef = new WeakReference<>(box.getSelectionModel());
SingleSelectionModel<String> replacingSm = ChoiceBoxShim.get_ChoiceBoxSelectionModel(box);
box.setSelectionModel(replacingSm);
attemptGC(10);
assertNull("selectionModel must be gc'ed", weakSmRef.get());
}
private void attemptGC(int n) {
// Attempt gc n times
for (int i = 0; i < n; i++) {
System.gc();
System.runFinalization();
if (weakSmRef.get() == null) {
break;
}
try {
Thread.sleep(500);
} catch (InterruptedException e) {
System.err.println("InterruptedException occurred during Thread.sleep()");
}
}
}
- relates to
-
JDK-8087555 [ChoiceBox] uncontained value not shown
- Resolved
-
JDK-8241737 TabPaneSkin memory leak on replacing selectionModel
- Resolved
-
JDK-8242489 ChoiceBox: initially toggle not sync'ed to selection
- Resolved