On 8/6/2026 2:52 PM, Kevin Rushforth wrote:
On 8/6/2026 1:33 PM, Dan Smith wrote:
On Aug 3, 2026, at 8:34 AM, Kevin Rushforth
<[email protected]> wrote:
First, some JavaFX UI controls APIs take a list of objects. JavaFX
internally creates a WeakReference to an individual object in some
cases. This is tracked by JDK-8387301 [2].
I was curious about the use cases, and how they might react to
different reference-clearing policies, so I dug into the code.
For TablePosition (#2 in JDK-8387301), turns out the WeakReference
seems to go unused: I can delete the private `itemRef` field and the
package-access `getItem` method, and everything still builds fine*.
(*Caveat that this is a complicated system, I’ve only built on macOS
and haven’t run any tests. Any reason to believe this is a
platform-specific dependency?)
I’ll keep looking at the other cases, see if they can provide any
insight into reference-clearing policies...
Thanks for looking into this. I know we don't rely on any reference
clearing behavior, but I haven't dug into how we are using those
WeakReferences in UI controls or whether we still need them at all
(unlike the WebView Java <--> JS bridge case where I know how and why
we are using them). It would be interesting to dig deeper to see if
they are needed at all for controls.
The private itemRef in TablePosition that you pointed out is indeed
unused and can be removed. The other three are still needed.
We don't rely on reference clearing behavior, so a simple wrapper will
suffice for our needs.
It looks like both the controls use and WebView use are going to be
fairly easy for us to fix in any case. I have a Draft PR out for the
UI controls weak references, if you would like to take a look and
offer feedback.
https://github.com/openjdk/jfx/pull/2250
I finished my testing and made the controls PR `rfr`.
-- Kevin