Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory Leak due to not pruning factoryBeanObjectCache when closing the ApplicationContext [SPR-15722] #20278

Closed
spring-issuemaster opened this issue Jun 30, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented Jun 30, 2017

Marten Deinum opened SPR-15722 and commented

For our, on Spring Boot based, project we have quite some integration tests. Some of these integration tests create a new application context due to custom configuration or the use of @MockBean.

To limit the number of cached contexts (as they are fairly large) we decided to reduce the number of cached context by setting the spring.test.context.cache.maxSize property to something less then 32.

However we noticed that after running some tests we were leaking memory. After fixing some issues with our own code (static references to the app context). We still noticed a leak.

After some digging we noticed that, amongst others, the JobRepositoryFactoryBean from Spring Batch kept hanging around. Which in turn had a reference to our JpaTransactionManager, which held on to the EntityManagerFactory all in all leaking around 50MB. Multiple this by a factor 30 and it starts to add up.

Some further digging lead to the discovery that a FactoryBean that doesn't implement DisposableBean or doesn't create instances which themselves are a DisposableBean they never get cleaned.

Our workaround is now to call getObject on the FactoryBean ourself. Which disables the registration of the FactoryBean and thus doesn't need to be cleaned up anymore. However would be nice if such a work-around wouldn't be needed.


Affects: 4.3.9

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jun 30, 2017

Marten Deinum commented

Pull Request for Repro Project: spring-projects/spring-framework-issues#161

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jun 30, 2017

Juergen Hoeller commented

Good point. We're clearing the factoryBeanObjectCache on destroySingletons now; we did that for individual singleton removal already but unfortunately not for a general shutdown yet...

I'll backport this to 4.3.10 right away. Please give it a try and let me know whether it works for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.