Re: RFR: 6507038: Memory Leak in JTree / BasicTreeUI [v6]

2024-01-31 Thread Prasanta Sadhukhan
On Wed, 31 Jan 2024 17:27:15 GMT, Alexey Ivanov  wrote:

>> src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTreeUI.java line 
>> 3284:
>> 
>>> 3282: if(tree != null) {
>>> 3283: rendererPane.removeAll();
>>> 3284: // Only ever removed when UI changes, this is OK!
>> 
>> The comment no longer applies—you remove all the components from 
>> `rendererPane` on the line above.
>
> This is the only important thing that prevents me from approving this PR. The 
> comment is misleading now.

OK, modified

-

PR Review Comment: https://git.openjdk.org/jdk/pull/17458#discussion_r1473741414


Re: RFR: 6507038: Memory Leak in JTree / BasicTreeUI [v6]

2024-01-31 Thread Alexey Ivanov
On Wed, 31 Jan 2024 17:13:55 GMT, Alexey Ivanov  wrote:

>> Prasanta Sadhukhan has updated the pull request incrementally with one 
>> additional commit since the last revision:
>> 
>>   Optimise test
>
> src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTreeUI.java line 
> 3284:
> 
>> 3282: if(tree != null) {
>> 3283: rendererPane.removeAll();
>> 3284: // Only ever removed when UI changes, this is OK!
> 
> The comment no longer applies—you remove all the components from 
> `rendererPane` on the line above.

This is the only important thing that prevents me from approving this PR. The 
comment is misleading now.

-

PR Review Comment: https://git.openjdk.org/jdk/pull/17458#discussion_r1473193899


Re: RFR: 6507038: Memory Leak in JTree / BasicTreeUI [v6]

2024-01-31 Thread Alexey Ivanov
On Wed, 31 Jan 2024 05:39:11 GMT, Prasanta Sadhukhan  
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:
> 
>   Optimise test

Changes requested by aivanov (Reviewer).

src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTreeUI.java line 
3284:

> 3282: if(tree != null) {
> 3283: rendererPane.removeAll();
> 3284: // Only ever removed when UI changes, this is OK!

The comment no longer applies—you remove all the components from `rendererPane` 
on the line above.

test/jdk/javax/swing/plaf/basic/BasicTreeUI/TreeCellRendererLeakTest.java line 
75:

> 73: 
> 74: // Create a new JLabel every time
> 75: public Component getTreeCellRendererComponent(

Suggestion:

// Create a new JLabel every time
@Override
public Component getTreeCellRendererComponent(

test/jdk/javax/swing/plaf/basic/BasicTreeUI/TreeCellRendererLeakTest.java line 
220:

> 218: }
> 219: }
> 220: 

One blank line in the end of a file is enough.

-

PR Review: https://git.openjdk.org/jdk/pull/17458#pullrequestreview-1854359018
PR Review Comment: https://git.openjdk.org/jdk/pull/17458#discussion_r1473178234
PR Review Comment: https://git.openjdk.org/jdk/pull/17458#discussion_r1473181636
PR Review Comment: https://git.openjdk.org/jdk/pull/17458#discussion_r1473189670


Re: RFR: 6507038: Memory Leak in JTree / BasicTreeUI [v6]

2024-01-30 Thread Prasanta Sadhukhan
> 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:

  Optimise test

-

Changes:
  - all: https://git.openjdk.org/jdk/pull/17458/files
  - new: https://git.openjdk.org/jdk/pull/17458/files/f7c9829b..047e25b5

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=17458&range=05
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=17458&range=04-05

  Stats: 15 lines in 1 file changed: 6 ins; 5 del; 4 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