Bug 460523 - [Contributions] CommandContributionItem are never disposed in 4.x?
Summary: [Contributions] CommandContributionItem are never disposed in 4.x?
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.5   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-02-21 14:39 EST by Andrey Loskutov CLA
Modified: 2019-12-22 06:46 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrey Loskutov CLA 2015-02-21 14:39:25 EST
Follow up on bug 420956 (see discussion on the patch https://git.eclipse.org/r/40448).

It looks like created CommandContributionItem instances are never disposed in 4.x (I'm on 4.5 M5 + HEAD changes). They seem not to be disposed neither in CPD nor on creating & closing new window. My naive attempt to dispose them (see diff below) failed because the corresponding toolbar buttons disappeared after opening/closing CPD dialog.

diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/CoolBarToTrimManager.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/CoolBarToTrimManager.java
index af4e3c9..8a6b9a2 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/CoolBarToTrimManager.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/CoolBarToTrimManager.java
@@ -295,6 +295,10 @@
 					if (OpaqueElementUtil.isOpaqueToolItem(element)) {
 						toRemove.add(element);
 					}
+					IContributionItem ci = renderer.getContribution(element);
+					if (ci != null) {
+						ci.dispose();
+					}
 				}
 				if (!toRemove.isEmpty()) {
 					toolbar.getChildren().removeAll(toRemove);

In Eclipse 3.8 they are disposed for example in this call tree:

Thread [main] (Suspended (breakpoint at line 762 in CommandContributionItem))   
        CommandContributionItem.dispose() line: 762     
        ToolBarManager.dispose() line: 159      
        ToolBarContributionItem2(ToolBarContributionItem).dispose() line: 162   
        CoolBarManager.dispose() line: 270      
        CustomizePerspectiveDialog$CustomizeActionBars.dispose() line: 1406     
        CustomizePerspectiveDialog.close() line: 3235   
        CustomizePerspectiveDialog(Dialog).cancelPressed() line: 488    
        CustomizePerspectiveDialog(Dialog).buttonPressed(int) line: 474 
        Dialog$2.widgetSelected(SelectionEvent) line: 624       
        TypedListener.handleEvent(Event) line: 248      
        EventTable.sendEvent(Event) line: 84    
        Button(Widget).sendEvent(Event) line: 1053      
        Display.runDeferredEvents() line: 4169  
        Display.readAndDispatch() line: 3758    
        CustomizePerspectiveDialog(Window).runEventLoop(Shell) line: 825        
        CustomizePerspectiveDialog(Window).open() line: 801     
        WorkbenchPage.editActionSets() line: 1970       
        EditActionSetsHandler.execute(ExecutionEvent) line: 41  
        HandlerProxy.execute(ExecutionEvent) line: 290  
        Command.executeWithChecks(ExecutionEvent) line: 499     
        ParameterizedCommand.executeWithChecks(Object, Object) line: 508        
        HandlerService.executeCommand(ParameterizedCommand, Event) line: 169    
        SlaveHandlerService.executeCommand(ParameterizedCommand, Event) line: 241       
        ActionFactory$WorkbenchCommandAction(CommandAction).runWithEvent(Event) line: 157       
        ActionContributionItem.handleWidgetSelection(Event, boolean) line: 584  
        ActionContributionItem.access$2(ActionContributionItem, Event, boolean) line: 501       
        ActionContributionItem$5.handleEvent(Event) line: 411   
        EventTable.sendEvent(Event) line: 84    
        MenuItem(Widget).sendEvent(Event) line: 1053    
        Display.runDeferredEvents() line: 4169  
        Display.readAndDispatch() line: 3758    
        Workbench.runEventLoop(Window$IExceptionHandler, Display) line: 2700    
        Workbench.runUI() line: 2664    
        Workbench.access$4(Workbench) line: 2498        
        Workbench$7.run() line: 679     
        Realm.runWithDefault(Realm, Runnable) line: 332 
        Workbench.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 668    
        PlatformUI.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 149   
        IDEApplication.start(IApplicationContext) line: 124     
        EclipseAppHandle.run(Object) line: 196  
        EclipseAppLauncher.runApplication(Object) line: 110     
        EclipseAppLauncher.start(Object) line: 79       
        EclipseStarter.run(Object) line: 353    
        EclipseStarter.run(String[], Runnable) line: 180        
        NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]  
        NativeMethodAccessorImpl.invoke(Object, Object[]) line: 57      
        DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 43  
        Method.invoke(Object, Object...) line: 606      
        Main.invokeFramework(String[], URL[]) line: 629 
        Main.basicRun(String[]) line: 584       
        Main.run(String[]) line: 1438   
        Main.main(String[]) line: 1414 

Is this a bug or feature???
Comment 1 Eclipse Genie CLA 2019-12-22 04:48:06 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 2 Rolf Theunissen CLA 2019-12-22 06:45:25 EST
I think this is a bug, all should be cleaned up when removed from a parent.

The disappearance of toolbar items in your naive approach is probably related to Bug 549898