Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-9851

Prevent memory leaks with @Configuration beans

    XMLWordPrintable

    Details

    • Last commented by a User:
      true

      Description

      I have an app where I create many spring contexts for 3rd party classes, so they can autowire some resources, work in restricted environment, basically some "plugin system". These contexts are created and destroyed dynamically, sometimes in rapid pace.

      Since I added support for custom javaconfig style context configuration, app started to produce PermGen errors. I traced it to the root of the problem, shown in this simple test:

      package springctx;
      
      import org.springframework.context.annotation.AnnotationConfigApplicationContext;
      
      public class SpringCtxTest {
      
      	public static void main(String[] args) {
      		while (true) {
      			AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(MyConfigClass.class);
      			ctx.destroy();
      		}
      	}
      
      }
      

      Config class:

      package springctx;
      
      import org.springframework.context.annotation.Configuration;
      
      @Configuration
      public class MyConfigClass {
      
      }
      

      When I run this, I can see clearly in VisualVM that PermGen is heading to the sky. Heapdump revealed gazillion of springctx.MyConfigClass$$EnhancerByCGLIB$$5d91109e entries in CachedIntrospectionResults

      When I run it without @Configuration annotation, everything is OK.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              cbeams Chris Beams
              Reporter:
              jmisur Juraj Misur
              Last updater:
              Spring Issues Spring Issues
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Days since last comment:
                3 years, 24 weeks, 5 days ago