On Mon, 28 Jun 2021 13:18:38 GMT, Marius Hanl <[email protected]> wrote:
>> The issue is about memory leaks and side-effects (like NPEs) when switching
>> skins.
>>
>> Details (copied from issue for convenience):
>>
>> memory leak in TextInputControlBehavior:
>> - listener accidentally added twice (removed once)
>> - keyPad mappings not properly installed/disposed
>>
>> memory leak TextFieldBehavior:
>> - listeners to scene/focusOwner property not removed,
>>
>> memory leak in TextInputControlSkin:
>> - event handlers related to inputMethods not removed
>>
>> issues in TextFieldSkin:
>> - memory leak due to behavior leaking
>> - memory leaks due to manually added change/invalidation listeners that are
>> not removed
>> - memory leaks due to not removing children with strong references to skin
>> - side-effects (f.i. NPEs) due to listeners/bindings that are still active
>> after dispose
>>
>> Fix was to properly install/remove those listeners/handlers. Added tests
>> that failed/passed before/after the fix, respectively, also added tests
>> passing before that must pass after the fix.
>
> modules/javafx.controls/src/main/java/javafx/scene/control/skin/TextFieldSkin.java
> line 390:
>
>> 388: @Override public void dispose() {
>> 389: if (getSkinnable() == null) return;
>> 390: getChildren().removeAll(textGroup, handleGroup);
>
> Also curious: Most of the skins don't remove their children in **dispose()**.
> Are they all wrong, or is this a special case here?
they are all wrong ;) When starting with the cleanup, we (me at least ;)
weren't yet entirely certain - but not removing them let them hang in the
hierarchy, reachable by strong references from their parent. Which in itself
isn't pretty (and might lead to unwanted side-effects) - but if they in turn
have any references to the skin (even not so obvious - for me again - like
being a not static nested class of the skin ;) the skin is strongly reachable
as well, making it leaky.
> modules/javafx.controls/src/test/java/test/com/sun/javafx/scene/control/behavior/BehaviorCleanupTest.java
> line 162:
>
>> 160: secondStage.hide();
>> 161: }
>> 162:
>
> minor: this empty line can be removed
yeah, can do .. but do we have conventions about vertical whitespace? Tend to
keep what suits my eyes :)
-------------
PR: https://git.openjdk.java.net/jfx/pull/534