Skip to content

Java config FactoryBean proxy causes class loader leak [SPR-9274] #13912

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Backported to: 3.2.9

5 votes, 5 watchers

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions