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_REQUESTED,
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