Project: Eclipse_Platform_UI
Bug 73872 [ActionSets] Action delegates promotes memory leaks
Reported: 2004-09-14 10:31:46 | Status: resolved fixed

The structure of the Action delegates (in particular ObjectAction) promotes memory leaks. What happens is the the typical implementation of a delegate will save the selection on the selectionChanged() or save the workbenchPart on the setActivePart() for ObjectAction. Object Action is the worst offender because the delegate lasts for the entire session once created. So if you popup a menu on one editor/view, and the delegate is called with setActivePart() and selectionChanged(), but that action is not selected, then the action (the ObjectPluginAction internal implementation itself AND the object delegate itself) hold onto the selection and the part. And then even though the selection has changed later or the part has been closed, they won't go away because they are being held onto. PluginAction holds onto the selection. And the selection can hold onto items from an editor, and these items can then go on and hold onto a editor. I've tested it with some of my own object delegates, and I held onto three different editors because of this (through the interaction of both the selection and the part being held onto). Even if I did something like make the selection and the part a WeakReference within my delegate it wouldn't matter because the main Action (PluginAction) will still hold onto the same things. And so I can't get rid of the leak.

Files changed in fix:
bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ObjectPluginAction.java bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/PluginAction.java