Bug 295391 [UI] EventBroker should clean up listeners that were subscribed to it
It would be really handy if the IEventBroker that exists in the appContext could cache up all the currently subscribed listeners and unsubscribe them when the appContext goes away. While you can say that the person who subscribed should be responsible for unsubscribing this is a fragile way to do it (i.e. Users don't RTFM and the unsubscribe pattern is not obvious). If it's not managed properly the OSGI context gets polluted with stale subscriptions which may cause very odd defects (hard to track down). Perhaps we should be looking to see if we can create these types of services using DI (so that they can have @PreDestroy injection). I also hope to do this with the SWT ResourceManager service, allowing it to clear its caches when its 'owning' appContext gets disposed.
bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/workbench/ui/internal/Workbench.java
Activator.trace(Policy.DEBUG_CMDS, "Initialize service from model", null); 
		ECommandService cs = (ECommandService) workbenchContext
				.get(ECommandService.class.getName());
		Category cat = cs
				.defineCategory(MApplication.class.getName(), "Application Category", null); 
		EList<MCommand> commands = workbench.getCommands();
		for (MCommand cmd : commands) {
			IParameter[] parms = null;
			String id = cmd.getId();
			String name = cmd.getCommandName();
			EList<MCommandParameter> modelParms = cmd.getParameters();
			if (modelParms != null && !modelParms.isEmpty()) {
				ArrayList<Parameter> parmList = new ArrayList<Parameter>();
				for (MCommandParameter cmdParm : modelParms) {
					parmList.add(new Parameter(cmdParm.getId(), cmdParm.getName(), null, null,
							cmdParm.isOptional()));
				}
				parms = parmList.toArray(new Parameter[parmList.size()]);
			}
			cs.defineCommand(id, name, null, cat, parms);
		}
		
		EList<MWindow> windows = workbench.getChildren();
		for (MWindow window : windows) {
			initializeContext(workbenchContext, window);
		}
		processHierarchy(workbench);
		
		((Notifier) workbench).eAdapters().add(new UIEventPublisher(workbench.getContext()));
	}