[Bug]: native macOS top bar menu memory leak
xVSTx opened this issue · comments
vst 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).
- 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;
-
Add a following line to the DemoTaskbarComponent constructor to avoid uninitialised main menu assertion failure:
juce::MenuBarModel::setMacMainMenu (&menu_model, nullptr);
-
Replace m.showMenuAsync() call in DemoTaskbarComponent::timerCallback() method with:
#if JUCE_MAC
showDropdownMenu(m);
#endif
- Press the top bar icon a few times (the Quit menu should appear at least twice)
- Call "leaks DemoRunner" in the terminal, NSMenu object(s) leak detected.
- 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];
}
}
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