Description
Juraj Misur opened SPR-9851 and commented
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.
Affects: 3.1.1
Sub-tasks:
- Backport "Prevent memory leaks with @Configuration beans" [SPR-9902] #14535 Backport "Prevent memory leaks with
@Configuration
beans"
Issue Links:
- MemoryLeak in Cglib2AopProxy.ProxyCallbackFilter [SPR-8008] #12663 MemoryLeak in Cglib2AopProxy.ProxyCallbackFilter
- Concurrent creation of the same Configuration class in different contexts is not thread-safe [SPR-10307] #14941 Concurrent creation of the same Configuration class in different contexts is not thread-safe