[ https://issues.apache.org/jira/browse/CXF-8745?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17679152#comment-17679152 ]
Eric commented on CXF-8745: --------------------------- Sorry, this has taken a long time for a very small snippet of code :) https://github.com/apache/cxf/pull/1077 > MemoryLeak when using SpringBus in a spring context which has a reusable > parent context > --------------------------------------------------------------------------------------- > > Key: CXF-8745 > URL: https://issues.apache.org/jira/browse/CXF-8745 > Project: CXF > Issue Type: Bug > Components: Bus > Affects Versions: 3.5.3 > Reporter: Eric > Priority: Minor > > SpringBus automatically registers itself as an ApplicationListener in the > SpringContext and recursively also in all its parents: > > {code:java} > 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(); > } > }{code} > 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. -- This message was sent by Atlassian Jira (v8.20.10#820010)