RFR: 8318841: macOS: Memory leak with MenuItem when Menu.useSystemMenuBar(true) is used [v2]
Johan Vos
jvos at openjdk.org
Mon Nov 6 18:08:14 UTC 2023
> When the Java layer removes a systemmenu, release the native resources related to this systemmenu.
> This removes the strong JNI Global ref, which prevents its references from being gc'ed.
>
> The current implementation for the mac-specific system menu creates a menu, but never releases its resources. In the `dealloc` of this menu, the strong jni refs are deleted.
> With this PR, we now release the native resources associated with a menuItem when that one is removed from a menu. A consequence is that this menuItem should never be used after being removed from its current menu (e.g. it should not be re-added, or its text/shortcut should not be altered).
> The current implementation will create a new MacMenuDelegate every time a menuItem is inserted into a menu, so there should be no references to the native resources lingering.
Johan Vos has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains three additional commits since the last revision:
- Check for null in the Java layer and avoid invoking native methods with a zero pointer.
Zero the relevant pointer in the MenuBarDelegate when a menu is removed.
- Merge remote-tracking branch 'upstream/master' into 8318841-macmenu
- When the Java layer removes a systemmenu, release the native resources related to this systemmenu.
This removes the strong JNI Global ref, which prevents its references from being gc'ed.
-------------
Changes:
- all: https://git.openjdk.org/jfx/pull/1277/files
- new: https://git.openjdk.org/jfx/pull/1277/files/f7664b02..5cf8c948
Webrevs:
- full: https://webrevs.openjdk.org/?repo=jfx&pr=1277&range=01
- incr: https://webrevs.openjdk.org/?repo=jfx&pr=1277&range=00-01
Stats: 651 lines in 32 files changed: 569 ins; 40 del; 42 mod
Patch: https://git.openjdk.org/jfx/pull/1277.diff
Fetch: git fetch https://git.openjdk.org/jfx.git pull/1277/head:pull/1277
PR: https://git.openjdk.org/jfx/pull/1277
More information about the openjfx-dev
mailing list