Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-8745

MemoryLeak when using SpringBus in a spring context which has a reusable parent context

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.5.3
    • 3.6.0, 4.0.1, 3.5.6, 3.4.11
    • Bus
    • None
    • Unknown

    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

          Activity

            People

              Unassigned Unassigned
              cheesemaster Eric
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: