RFR: 6507038: Memory Leak in JTree / BasicTreeUI [v3]

Prasanta Sadhukhan psadhukhan at openjdk.org
Wed Jan 31 05:39:12 UTC 2024


On Tue, 30 Jan 2024 10:38:03 GMT, Alexey Ivanov <aivanov at openjdk.org> wrote:

>> I was not sure of the nuances of PhantomReference and ReferenceQueue, so have used WeakReference logic in the test which I think is more simpler..
>
> It's simpler with `PhantomReference`. This type of reference does not allow getting its referent, and it's not needed in this case. When the referent of a reference is cleared by the GC, the reference is added into the associated reference queue. This is true for any type of `Reference`, but `PhantomReference` has to use a reference queue.
> 
> Here's how to use them: https://github.com/aivanov-jdk/jdk/commit/b0da8b30fdcf03abffa663eb5ba42df1fe4a9971
> 
> I keep the references in a list. The size of the list is the number of live `JLabel` objects. On each iteration, I poll the reference queue and remove the _dead_ references from the list.
> 
> https://github.com/openjdk/jdk/blob/b0da8b30fdcf03abffa663eb5ba42df1fe4a9971/test/jdk/javax/swing/plaf/basic/BasicTreeUI/TreeCellRendererLeakTest.java#L193-L201
> 
> If the number of removed references is zero, the test fails because objects are leaked. Otherwise, the test passes. This aligns with your latest changes.
> 
> Your code also does the job. I'll approve it if you don't want to use `PhantomReference`.

Thanks for your "reference" on PhantomReference..Although my testcode is doing same thing (which you acknowledged) no harm in trying new way (for me) for my future reference so have updated the test to use PhantomReference.

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

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


More information about the client-libs-dev mailing list