RFR: 6507038: Memory Leak in JTree / BasicTreeUI [v8]
Harshitha Onkar
honkar at openjdk.org
Wed Feb 7 00:20:00 UTC 2024
On Thu, 1 Feb 2024 03:16:27 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..
>
> Prasanta Sadhukhan has updated the pull request incrementally with one additional commit since the last revision:
>
> Test updated
test/jdk/javax/swing/plaf/basic/BasicTreeUI/TreeCellRendererLeakTest.java line 30:
> 28: * @summary Verifies memory leak in BasicTreeUI TreeCellRenderer
> 29: * @run main TreeCellRendererLeakTest
> 30: */
jtreg header can be moved to _before class declaration_ location.
test/jdk/javax/swing/plaf/basic/BasicTreeUI/TreeCellRendererLeakTest.java line 111:
> 109: }
> 110:
> 111: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
Editor Code Folding can be removed to avoid this code being collapsed in IDE.
test/jdk/javax/swing/plaf/basic/BasicTreeUI/TreeCellRendererLeakTest.java line 117:
> 115: jScrollPane1 = new javax.swing.JScrollPane();
> 116: jTree1 = new javax.swing.JTree();
> 117: jPanel2 = new javax.swing.JPanel();
Fully qualified class name are redundant here since we already have the required imports.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/17458#discussion_r1480676447
PR Review Comment: https://git.openjdk.org/jdk/pull/17458#discussion_r1480700180
PR Review Comment: https://git.openjdk.org/jdk/pull/17458#discussion_r1480675309
More information about the client-libs-dev
mailing list