Possible workarounds would be to use Control.setSkin instead of -fx-skin, or to 
bind the skin property after it has been set to something other than the 
default.  CSS should not mess with a bound property.

> -----Original Message-----
> From: openjfx-dev <openjfx-dev-boun...@openjdk.java.net> On Behalf Of
> Adam Granger
> Sent: Thursday, January 9, 2020 3:04 AM
> To: openjfx-dev@openjdk.java.net
> Subject: [EXTERNAL] Memory leak in JavaFX 8 when changing skins
> 
> 
> Greetings,
> 
> I realise this is now legacy for most people but we still widely use JavaFX 8.
> 
> I appear to have discovered a memory leak when skin is changed
> 
> The constructor
> com.sun.javafx.scene.control.skin.BehaviorSkinBase.BehaviorSkinBase
> adds an event listener
> 
>    control.addEventHandler(ContextMenuEvent.CONTEXT_MENU_REQUESTE
> D,
> contextMenuHandler);
> 
> However this is never removed in the dispose() which prevents garbage
> collection of the previous skin.
> 
> This problem is amplified by fact JavaFX appears to reload skins unnecessarily
> in a complex use case involving JFXPanel  - I've as-yet been unable to
> produce a SSCCE for this
> 
> What I've discovered so far
>  - CSS is reprocessed
> 
>  - javafx.scene.CssStyleHelper.canReuseStyleHelper(Node, StyleMap)
> returns false
>  - node.styleHelper.resetToInitialValues(node); is called which then causes
> the "stock" skin load
>  - custom skin (-fx-skin in our application CSS) is then loaded
> 
>  - stock skin cannot be GC'd and neither can our custom skin
>  - appears to affect any subclass of BehaviorSkinBase
> 
> Please could you confirm my analysis of this problem and suggest any
> workarounds?
> 
> Regards,
> 
> Adam

Reply via email to