DefaultListableBeanFactorys leaking memory
Environment
- JBoss Enterprise Application Platform (EAP)
- Spring 3.0.0 or later
Issue
- A lot of memory is being retained by org.springframework.beans.factory.support.DefaultListableBeanFactory objects leading to OutOfMemoryErrors
Resolution
Disclaimer: Links contained herein to external website(s) are provided for convenience only. Red Hat has not reviewed the links and is not responsible for the content or its availability. The inclusion of any link to an external website does not imply endorsement by Red Hat of the website or their entities, products or services. You agree that Red Hat is not responsible or liable for any loss or expenses that may result due to your use of (or reliance on) the external site or content.
If using Spring version 3.0.4 or earlier, ensure that all contexts are refreshed and then closed when done with them.
If using Spring version 3.0.5 or later, ensure that all contexts are at least closed when done with them.
Root Cause
Starting with spring 3.0.0, a org.springframework.beans.factory.support.DefaultListableBeanFactory entry is stored in a ConcurrentHashMap called serializableFactories when a context is created. If the context is not properly closed, this entry will not be cleaned up.
There is a bug in spring 3.0.4 or earlier that prevents these entries from being cleaned up when a context is closed after never being refreshed:
https://jira.springsource.org/browse/SPR-7502
Diagnostic Steps
- Troubleshoot as described in Java application "java.lang.OutOfMemoryError: Java heap space" and verify the source of retention
- Check for retention associated with this object
- Verify that Contexts are being properly closed
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.