[ 
https://issues.apache.org/jira/browse/CXF-8745?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17597639#comment-17597639
 ] 

Colm O hEigeartaigh commented on CXF-8745:
------------------------------------------

Hi, can you consider opening a pull request for this issue?

> 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)

Reply via email to