Details
Description
SpringBus automatically registers itself as an ApplicationListener in the SpringContext and recursively also in all its parents:
public void setApplicationContext(ApplicationContext applicationContext) { ctx = (AbstractApplicationContext)applicationContext; @SuppressWarnings("rawtypes") ApplicationListener listener = new ApplicationListener() { public void onApplicationEvent(ApplicationEvent event) { SpringBus.this.onApplicationEvent(event); } }; ctx.addApplicationListener(listener); ApplicationContext ac = applicationContext.getParent(); while (ac != null) { if (ac instanceof AbstractApplicationContext) { ((AbstractApplicationContext)ac).addApplicationListener(listener); } ac = ac.getParent(); } }
This leads to a MemoryLeak when the current SpringContext is closed but the ParentContext is reused for another child context, because the ApplicationListener references the SpringBus and the SpringBus references the old ApplicationContext.
A very simple approach to solve this problem would be to deregister the listener in a destroy-block or to just use a WeakReference. The later is also used by spring itself when they register a listener in the parent to automatically close all related child contexts.
Attachments
Issue Links
- links to