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
/**
	 * Create the context chain. It both creates the chain for the current model, and adds eAdapters
	 * so it can add new contexts when new model items are added.
	 * 
	 * @param parentContext
	 *            The parent context
	 * @param contextModel
	 *            needs a context created
	 */
	public static IEclipseContext initializeContext(IEclipseContext parentContext,
			MContext contextModel) {
		final IEclipseContext context;
		if (contextModel.getContext() != null) {
			context = contextModel.getContext();
		} else {
			context = EclipseContextFactory
					.create(parentContext, UISchedulerStrategy.getInstance());
			context.set(IContextConstants.DEBUG_STRING, "PartContext(" + contextModel + ')'); 
		}
		Activator.trace(Policy.DEBUG_CONTEXTS, "initializeContext(" 
				+ parentContext.toString() + ", " + contextModel + ")", null); 
		
		
		final Class[] interfaces = contextModel.getClass().getInterfaces();
		for (Class intf : interfaces) {
			Activator.trace(Policy.DEBUG_CONTEXTS, "Adding " + intf.getName() + " for " 
					+ contextModel.getClass().getName(), null);
			context.set(intf.getName(), contextModel);
		}