Description
Harald Wellmann opened SPR-9274 and commented
Redeploying my web application in Tomcat a couple of times in a row, I had a PermGen space OutOfMemoryError. A heap dump revealed the cause to be a net.sf.cglib.proxy.Callback stored in thread-local memory, so that the associated class loader could not get garbage collected.
The callback holds a reference to ConfigurationClassEnhancer.GetObjectMethodInterceptor, which brought me closer to the root cause of the problem.
After changing my Spring Configuration from
@Bean
public PlatformTransactionManager transactionManager() {
return new JpaTransactionManager(myEntityManagerFactory().getObject());
}
@Bean
public AbstractEntityManagerFactoryBean myEntityManagerFactory() {
LocalContainerEntityManagerFactoryBean bean = new LocalContainerEntityManagerFactoryBean();
bean.setDataSource(myDataSource);
bean.setPersistenceProvider(new HibernatePersistence());
bean.setPersistenceUnitName("myPU");
return bean;
}
to
@Bean
public PlatformTransactionManager transactionManager() {
return new JpaTransactionManager(myEntityManagerFactory());
}
@Bean
public EntityManagerFactory tcmEntityManagerFactory() {
LocalContainerEntityManagerFactoryBean bean = new LocalContainerEntityManagerFactoryBean();
bean.setDataSource(myDataSource);
bean.setPersistenceProvider(new HibernatePersistence());
bean.setPersistenceUnitName("myPU");
bean.afterPropertiesSet();
return bean.getObject();
}
I can redeploy my application without memory leaks.
I suspect the problem would disappear if ConfigurationClassEnhancer.enhanceFactoryBean() called Enhancer.registerStaticCallbacks() instead of Enhancer.registerCallbacks() (see #10601).
Affects: 3.1 GA, 3.2.8
Issue Links:
- 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
- Singleton-scoped @Bean methods behave like prototypes in a Spring DM environment [SPR-5932] #10601 Singleton-scoped
@Bean
methods behave like prototypes in a Spring DM environment
Backported to: 3.2.9
5 votes, 5 watchers