Project: Eclipse_Platform_UI
Bug 295391 [UI] EventBroker should clean up listeners that were subscribed to it
Reported: 2009-11-17 16:02:19 | Status: resolved fixed

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.

Files changed in fix:
bundles/org.eclipse.e4.ui.services/src/org/eclipse/e4/ui/services/events/EventBrokerFactory.java bundles/org.eclipse.e4.ui.services/src/org/eclipse/e4/ui/services/internal/events/EventBroker.java bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/internal/E4Application.java bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/workbench/swt/internal/WorkbenchApplication.java bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/workbench/ui/internal/Workbench.java tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/application/HeadlessStartupTest.java