Leak when adding CustomComponent to a PopupMenu

Hi, I am unsure if my way of using the ComboBox to have a PopupMenu displaying CustomComponent. It seems like my CustomComponent won’t be deleted after I clear the PopupMenu. Here is the simplest example:

PopupMenu* lPopupMenu = mComboBox->getRootMenu();

PopupMenu::Item i;
i.itemID = mComboBox->getNumItems() + 1;
std::unique_ptr<MenuItemDeletableMetaData> lDeletable = std::make_unique<MenuItemDeletableMetaData>();
i.customComponent = lDeletable.release();
i.text = aName;
lPopupMenu->addItem(i);
// i clear it here for the example and expect the Menu item to be deleted
// but it is not.
lPopupMenu->clear();

Is there something I am doing wrong? I am with JUCE 5.4.7.

It needs to be reference counted. your custom component needs to inherit from CustomComponent and be instantiated via new.

item.customComponent = new Comp();

https://docs.juce.com/master/structPopupMenu_1_1Item.html#a025d6b228217e54bb2f2c5aee687eee0

https://docs.juce.com/master/classPopupMenu_1_1CustomComponent.html