RFR: 8263402: MemoryLeak: Node hardreferences it's previous Parent after csslayout and getting removed from the scene

Kevin Rushforth kcr at openjdk.java.net
Thu Mar 11 22:01:07 UTC 2021


On Wed, 10 Mar 2021 22:30:27 GMT, Kevin Rushforth <kcr at openjdk.org> wrote:

>> Fixing a memory leak. 
>> A node hard references its old parent after CSS layout and getting removed. 
>> This shouldn't be the case, this is very counterintuitive.
>> 
>> The fix uses a WeakReference in CSSStyleHelper for firstStyleableAncestor.
>> This should be fine because the CSS should only depend on it if it's still the real parent. 
>> In that case, it doesn't get collected.
>
> Since this touches CSS, it needs a second reviewer.

I think others can review this. I do have a couple questions:
1. In general, I don't like the idea of just making everything a weak reference, since it often masks a design issue. Two exceptions are for caches and for back references to a "parent" or controlling object that has a strong reference to "this" object (most of our weak listeners fall into this latter pattern). It sounds like latter case also applies here. Can you confirm that?
2. Have you verified that all the places that use the fields that are now WeakReferences are prepared to deal with `get()` returning a null object?

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

PR: https://git.openjdk.java.net/jfx/pull/424


More information about the openjfx-dev mailing list