Take the 2-minute tour ×   1. When is a Spring container
(XMLBeanFactory) gracefully unloaded by Spring?   2. What
happens when the application is running but the only handler to
the BeanFactory goes out of scope?   3. What is the ideal way to
load a Spring Container? Is doing handler = new BeanFactory()
the right approach?  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.  share|improve this question
2 Answers 2  up vote 2 down vote accepted   1. This depends on
how you're instantiating