RFR: 6507038: Memory Leak in JTree / BasicTreeUI

Prasanta Sadhukhan psadhukhan at openjdk.org
Wed Jan 17 07:27:28 UTC 2024


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..

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

Commit messages:
 - 6507038: Memory Leak in JTree / BasicTreeUI

Changes: https://git.openjdk.org/jdk/pull/17458/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=17458&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-6507038
  Stats: 3 lines in 1 file changed: 3 ins; 0 del; 0 mod
  Patch: https://git.openjdk.org/jdk/pull/17458.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/17458/head:pull/17458

PR: https://git.openjdk.org/jdk/pull/17458


More information about the client-libs-dev mailing list