Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: native macOS top bar menu memory leak #1375

Open
1 task done
xVSTx opened this issue Apr 5, 2024 · 0 comments
Open
1 task done

[Bug]: native macOS top bar menu memory leak #1375

xVSTx opened this issue Apr 5, 2024 · 0 comments

Comments

@xVSTx
Copy link

xVSTx commented Apr 5, 2024

Detailed steps on how to reproduce the bug

A problem could be reproduced on a modified DemoRunner example (modified Main.cpp -> Main.txt attached).

  1. Add a dummy menu_model_t class to the top of Main.cpp:
class menu_model_t : public juce::MenuBarModel
{
public:
    menu_model_t(){}
    juce::StringArray getMenuBarNames() override {return {};}
    juce::PopupMenu getMenuForIndex (int topLevelMenuIndex, const juce::String& menuName) override
    {
        juce::PopupMenu empty_menu;
        return empty_menu;
    }
    void menuItemSelected (int menuItemID, int topLevelMenuIndex) override {}
};
menu_model_t menu_model;
  1. Add a following line to the DemoTaskbarComponent constructor to avoid uninitialised main menu assertion failure:
    juce::MenuBarModel::setMacMainMenu (&menu_model, nullptr);

  2. Replace m.showMenuAsync() call in DemoTaskbarComponent::timerCallback() method with:

#if JUCE_MAC
         showDropdownMenu(m);
#endif
  1. Press the top bar icon a few times (the Quit menu should appear at least twice)
  2. Call "leaks DemoRunner" in the terminal, NSMenu object(s) leak detected.
  3. Adding [m release]; to void showMenu (const PopupMenu& menu) method solves the issue (juce_SystemTrayIcon_mac.cpp).
void showMenu (const PopupMenu& menu)
{
  if (NSMenu* m = createNSMenu (menu, "MenuBarItem", -2, -3, true))
  {
    setHighlighted (true);
    stopTimer();
    
    // There's currently no good alternative to this.
    [statusItem.get() popUpStatusItemMenu: m];
    
    startTimer (1);
    [m release];
  }
}

Main.txt

leaks_DemoRunner.txt

DemoRunner.zip

What is the expected behaviour?

NSMenu is not leaking

Operating systems

macOS

What versions of the operating systems?

Any, but tested on 14.4

Architectures

ARM

Stacktrace

No response

Plug-in formats (if applicable)

Standalone

Plug-in host applications (DAWs) (if applicable)

No response

Testing on the develop branch

I have not tested against the develop branch

Code of Conduct

  • I agree to follow the Code of Conduct
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant