- When is a Spring container (XMLBeanFactory) gracefully unloaded by Spring?
- What happens when the application is running but the only handler to the BeanFactory goes out of scope?
- What is the ideal way to load a Spring Container? Is doing
handler = new BeanFactory()the right approach?
Update:
When container goes out of scope, we would indeed expect the close() method to be called which would in turn release all the held resources. But that does not happen! I encountered a case where I had spring containers going out of scope but still memory getting full (OutOfMemory error). The reason was that the SessionFactory objects created by my Spring containers never got garbage collected as they are created as static. This implies that close()->destroy() was never called when containers went out of scope. Makes me believe that there is a leak issue with Spring itself.
and then later on you close it:
For webapps: