Right, that's what I had in mind.
On 8/11/2026 8:00 PM, Kevin Rushforth wrote:
That's an interesting idea. Something like this I guess?
public static <T> Reference<T> weakOrNeverClearedReference(T ref);
(with a more sensible name)
-- Kevin
On 8/7/2026 11:57 AM, Brian Goetz wrote:
One way to do this more generally would be to have a subtype
NeverClearedReference of Reference, and then have a factory method
that inspects the argument and returns either a WR or a NCR, typed as
Reference. Since WR has no functionality over that of Reference,
existing code should be able to use it as it uses WRs. Reference is
sealed but already has encapsulated subtypes so won't perturb any
existing switches. If FX encountered this, other frameworks will as
well, and this might be a reasonable stopgap until we have a better
story for WHM.
On 8/6/2026 5: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.
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
-- Kevin