On Tue, 30 Jan 2024 15:35:54 GMT, Alexey Ivanov <[email protected]> wrote:
>> Prasanta Sadhukhan has updated the pull request incrementally with one
>> additional commit since the last revision:
>>
>> Use removeAll and testcase modified
>
> test/jdk/javax/swing/plaf/basic/BasicTreeUI/TreeCellRendererLeakTest.java
> line 204:
>
>> 202: count++;
>> 203: }
>> 204: }
>
> You have to iterate over `weakRefArrLabel` in a synchronized block. (No,
> declaring `weakRefArrLabel` as `volatile` is not enough.)
> Suggestion:
>
> synchronized (weakRefArrLabel) {
> for (WeakReference<JLabel> ref : weakRefArrLabel) {
> if (ref.get() == null) {
> count++;
> }
> }
> }
Alternatively, you can use Stream API:
private long getCleanedUpLabelCount() {
synchronized (weakRefArrLabel) {
return weakRefArrLabel.stream()
.filter(r -> r.get() != null)
.count();
}
}
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/17458#discussion_r1471461777