juce-framework / JUCE

JUCE is an open-source cross-platform C++ application framework for desktop and mobile applications, including VST, VST3, AU, AUv3, LV2 and AAX audio plug-ins.

Home Page:https://juce.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug]: native macOS top bar menu memory leak

xVSTx opened this issue · comments

commented

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