Skip to content

Prevent memory leaks with @Configuration beans [SPR-9851] #14484

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Issue Links:

Referenced from: commits 27c8371, ced6bb4, c806139

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions