On Wed, 31 Jan 2024 05:35:44 GMT, Prasanta Sadhukhan <psadhuk...@openjdk.org> wrote:
>> 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. Could you add me as contributor, please? ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/17458#discussion_r1473192053