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;
// i clear it here for the example and expect the Menu item to be deleted
// but it is not.

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();