RFR: 8263402: MemoryLeak: Node hardreferences it's previous Parent after csslayout and getting removed from the scene [v4]
Kevin Rushforth
kcr at openjdk.java.net
Wed Apr 7 13:49:15 UTC 2021
On Wed, 7 Apr 2021 13:10:29 GMT, Kevin Rushforth <kcr at openjdk.org> wrote:
>> Florian Kirmaier has updated the pull request incrementally with one additional commit since the last revision:
>>
>> 8263402
>> Minor cleanup based on codereview
>
> modules/javafx.graphics/src/main/java/javafx/scene/CssStyleHelper.java line 355:
>
>> 353: /* This is the first Styleable parent (of Node this StyleHelper belongs to)
>> 354: * having a valid StyleHelper */
>> 355: private WeakReference<Node> firstStyleableAncestor = null;
>
> Since `firstStyleableAncestor` is initialized to `null`, rather than `new WeakReference(null)`, it might be possible for a call to `firstStyleableAncestor.get()` to throw an NPE. Can you comment on what analysis and testing you've done to ensure that this won't happen in some situations? A quick look shows that in the two places a `CssStyleHelper` object is created, `firstStyleableAncestor` is set shortly after, but it wouldn't hurt to take a closer look.
One solution would be to create an `EMPTY_NODE` singleton and initialize it to that:
private static final WeakReference<Node> EMPTY_NODE = new WeakReference<>(null);
private WeakReference<Node> firstStyleableAncestor = EMPTY_NODE;
-------------
PR: https://git.openjdk.java.net/jfx/pull/424
More information about the openjfx-dev
mailing list