You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following pattern is often seen in code using MenuManager:
menuManager.setRemoveAllWhenShown(true);
menuManager.addMenuListener(newIMenuListener() {
@OverridepublicvoidmenuAboutToShow(IMenuManagermanager) {
// add stuff to the manager dynamically depending on some state
}
});
The ContributionItems added in the IMenuListener are removed before the next invocation of menuAboutToShow(), but their dispose() method is not also called. This assumes that Contribution items are created only once, and the instances are re-used between calls to menuAboutToShow(). This was not clear to me at all. I have tons of code which creates MenuManagers on the fly, or directly calls menu.add(actionInstance), which creates an anonymous ActionContributionItem that noone keeps a reference to when it is removed via setRemoveAllWhenShown(true).
If I am not mistaken MenuManager.dispose() and other implementations of IContributionItem.dispose() are written in such a way that the item remains useable. Resources are simply recreated when needed. Either the dispose() hook should be called when removing all items, or at least the documentation should make it very clear that this is what needs to be done by the user of the API.
The text was updated successfully, but these errors were encountered:
mickaelistria
pushed a commit
to mickaelistria/eclipse.platform.ui
that referenced
this issue
Oct 6, 2023
The following pattern is often seen in code using
MenuManager
:The
ContributionItem
s added in theIMenuListener
are removed before the next invocation ofmenuAboutToShow()
, but theirdispose()
method is not also called. This assumes that Contribution items are created only once, and the instances are re-used between calls tomenuAboutToShow()
. This was not clear to me at all. I have tons of code which creates MenuManagers on the fly, or directly calls menu.add(actionInstance), which creates an anonymousActionContributionItem
that noone keeps a reference to when it is removed viasetRemoveAllWhenShown(true)
.If I am not mistaken
MenuManager.dispose()
and other implementations ofIContributionItem.dispose()
are written in such a way that the item remains useable. Resources are simply recreated when needed. Either thedispose()
hook should be called when removing all items, or at least the documentation should make it very clear that this is what needs to be done by the user of the API.The text was updated successfully, but these errors were encountered: