RFR: 6507038: Memory Leak in JTree / BasicTreeUI

Harshitha Onkar honkar at openjdk.org
Thu Jan 18 00:26:40 UTC 2024


On Wed, 17 Jan 2024 07:19:21 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:

> When using a TreeCellRenterer which creates new components in getTreeCellRendererComponent() in a JTree that is not visible, changes to the nodes cause a memory leak.
> When a node is changed, the Method getNodeDimensions() is called to calculate the new dimensions for the node. In this method, getTreeCellRendererComponent() is called to obtain the renderer component (what else...) and [this component is added to rendererPane](https://github.com/openjdk/jdk/blob/36f4b34f1953af736706ec67192204727808bc6c/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTreeUI.java#L3283-L3284). It is not removed from the rendererPane afterwards. 
> Only when the tree is painted, the paint() method does a removeAll on the rendererPane [in this code](https://github.com/openjdk/jdk/blob/36f4b34f1953af736706ec67192204727808bc6c/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTreeUI.java#L1500)
> 
> FIx is added to remove the components from rendererPane when the JTree UI is changed/uninstalled only when tree is not visible since they are already removed when tree is painted in paint() method..

Ran the reproducer attached to JBS without and with the fix. The "Live Label count" seem to increase in both cases.
After running the test, I switched to tab 2, which makes tab 1 (with JTree) inactive but during this time the Live label count increase.
Will a test case be added as part of this fix? 


Live TestLabels:0
Live TestLabels:74
Live TestLabels:57
Live TestLabels:21
Live TestLabels:60
Live TestLabels:46
Live TestLabels:62
Live TestLabels:102
Live TestLabels:140
Live TestLabels:180
Live TestLabels:218
Live TestLabels:256
Live TestLabels:296
Live TestLabels:334
Live TestLabels:374
Live TestLabels:412
Live TestLabels:452
Live TestLabels:490

-------------

PR Review: https://git.openjdk.org/jdk/pull/17458#pullrequestreview-1828473222


More information about the client-libs-dev mailing list