Project: Eclipse_Platform_UI
Bug 398381 [Contributions] Memory leak when ever calling context menu
Reported: 2013-01-17 07:15:19 | Status: resolved fixed

Steps to reproduce: Call a context menu in a view/editor more times The memory leak happens when calling a context menu in the Package Explorer view, the Java editor, the Outline view ... Many contribution items and elements are leaked. The issue happens for the following two reasons: - the PopupMenuExtender class seems to have to call the unlink method when the context menu is hidden. - the MenuManagerRendere class contains the sharedElementToRecord hash map that uses MMenuElement as a key. The classes that implement the MMenuElement interface don't override hashCode (and equals), but the ContributionRecord.mergeIntoModel method clones those elements that are contributed using the 'popup:org.eclipse.ui.popup.any' uri. That's why the sharedElementToRecord hash map contains leaked elements. I have solved the issue so that the PopupMenuExtender remembers such entries and clears them when the menu is hidden. Attached is a patch.

Files changed in fix:
bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/ContributionRecord.java bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/MenuManagerRenderer.java