[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openjdk-openjfx-dev
Subject:    Re: Detecting memory leaks in a Scene
From:       John Hendrikx <hjohn () xs4all ! nl>
Date:       2021-03-28 12:42:59
Message-ID: e6f85554-14bb-b4d0-aa10-db7cff9e40ec () xs4all ! nl
[Download RAW message or body]

Hah, managed to reproduce it in a small sample program.  Filed bug:

https://bugs.openjdk.java.net/browse/JDK-8264330

--John

On 28/03/2021 14:03, John Hendrikx wrote:
> I've created a bit of helper code I've been using to detect Nodes that
> have been removed from a Scene that are not getting garbage collected.
>
> It takes a Scene as input, and will then monitor all Nodes that are
> added and removed to compile a list of Nodes that are no longer part of
> the Scene but are still being referenced.
>
> The code is here:
> https://gist.github.com/hjohn/f7b2d5b6d56ba5e5bb6b6c5621799ca5
>
> One major issue I've already discovered with this code (apart from my
> own mistakes) is that Scene$MouseHandler is holding on to references to
> Nodes that it thinks might be part of a future drag/drop action. It does
> this in the pdrEventTargets fields. I haven't been able to reproduce
> this yet in a small sample program, but in my larger program I
> can reproduce it at any time:
>
>     1) Hover over a component
>
>     2) Trigger some action with the keyboard which replaces or removes
> the hovered component
>
>     3) References to the replaced nodes still exist in pdrEventTargets
> (seen with VisualVM)
>
> The references disappear as soon as you press a mouse button (moving the
> mouse around isn't sufficient). Note that I'm not doing any drag'n'drop
> type actions nor do I use any drag'n'drop things in my program (it is
> fully keyboard controlled).
>
> There is code in Scene$MouseHandler to apparently deal with this case
> where a node gets removed, but it doesn't seem to help in a more complex
> UI. I'll attempt to debug this further, but would also appreciate any
> help if someone knows that code.
>
> The removal code:
>
>     /**
>      * Generates mouse exited event for a node which is going to be removed
>      * and its children, where appropriate.
>      * @param removing Node which is going to be removed
>      */
>     void generateMouseExited(Node removing) {
>         mouseHandler.handleNodeRemoval(removing);
>     }
>
> In the "handleNodeRemoval" a lot of things are happening, but a lot of
> it is skipped when certain conditions aren't met (like "pdrInProgress").
> As there won't be a DnD in progress I think the references are not being
> removed from the arraylists the MouseHandler is maintaining.
>
> Anyway, I hope the leak detecting code will be useful, I've been toying
> around with something like this for quite a while, and now that I've got
> something that is actually really useful for detecting leaks as soon as
> they happen I thought it be good to share.
>
> --John
>
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic