On Thu, 5 Jan 2023 08:34:14 GMT, Florian Kirmaier <fkirma...@openjdk.org> wrote:

>> This PR fixes the leak in the mac system menu bar.
>> 
>> Inside the native code, NewGlobalRef is called for the callable.
>> Which makes it into a "GC-Root" until DeleteGlobalRef is called.
>> 
>> The DeleteGlobalRef is never called for the MenuEntry, if it's removed from 
>> the menu without removing it's callable.
>> This PR adds logic, whether the Menu is inserted. If it's not inserted in a 
>> Menu anymore, then DeleteGlobalRef is called, by calling `_setCallback` with 
>> the callable "null".
>> 
>> The unit test verifies, that this bug happened without this change, but no 
>> longer happens with this change.
>
> Florian Kirmaier has updated the pull request incrementally with two 
> additional commits since the last revision:
> 
>  - JDK-8299423
>    reverted added newline
>  - JDK-8299423
>    reverted whitespace change,
>    added missing copyright header

I've tested this version with explicit GC, and it still worked. So i guess it's 
stable.

Ok, so now there are multiple Solutions:

1. Revert to the previous version, and remove the WeakReference again.
2. Add an explicit reference to the Callable in the MacMenuDelegate. This would 
make proof reading much easier.
3. Keep it as is.

I guess I would prefer 2. Would that be ok for everyone?

@mstr2 
I guess this would have to be done in this method:


- (void)action:(id)sender
{
    if (self->jCallback != NULL)
    {
        GET_MAIN_JENV;
        if (env != NULL)
        {
            (*env)->CallVoidMethod(env, self->jCallback, jMenuActionMethod, 
NULL);
        }
    }
}

Do you have an example, of how this should look like? I'm neither familiar with 
C, Objective-C, or this JNI code.

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

PR: https://git.openjdk.org/jfx/pull/987

Reply via email to