RFR: 8319779: SystemMenu: memory leak due to listener never being removed [v4]

Johan Vos jvos at openjdk.org
Mon Dec 18 13:21:51 UTC 2023


On Mon, 18 Dec 2023 13:18:02 GMT, Johan Vos <jvos at openjdk.org> wrote:

>> A listener was added but never removed.
>> This patch removes the listener when the menu it links to is cleared. Fix for https://bugs.openjdk.org/browse/JDK-8319779
>
> Johan Vos has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Fix more memoryleaks due to listeners never being unregistered.

As for the testing issue: the memoryleak before this fix leads to an increasing number of `com.sun.glass.ui.MenuItem` instances.
We could test the previous memoryleak, as that was creating an increasing number of `javafx.scene.control.MenuItem` instances, which could be handled inside a JavaFX application and stored as WeakReferences in a list, that could then be required to be empty after GC.
Our systemtest does not have access to the `com.sun.glass.ui.MenuItem` instances, so we can't use the same approach. In theory, it should be possible to mock the whole path that leads to this leak, but it is complex.
I do understand the value of tests for this, though, as the fix is brittle. When a new InvalidationListener is added referencing the to-be-removed menuItems, the memoryleak will re-occur and go unnoticed.

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

PR Comment: https://git.openjdk.org/jfx/pull/1283#issuecomment-1860481040


More information about the openjfx-dev mailing list