Jayesh A Lalwani wrote:Beans are kept in memory as long as they are in scope. If the are singleton scoped they will stay in memory as long as the application context is in memory. If you don't want to keep the bean in memory, you should use a differrent scope. Prototype scope will create and destroy the bean everytime you request it from app context. The lifetime of session scoped beans will be limited to the web session. THe lifetime of request scoped beans will be limited to the HTTP request.
If you want a differrent mechanism for controlling the lifetime of beans, you will have to define a custom scope.
Lazy Loading pattern doesn;t save memory for objects that are always going to be used. Lazy Loading pattern prevents objects that are seldom used from loading at startup. If you want objects to die off after they have not been used for a while, you need to have some sort of Pooling mechanism that destroys objects that are not used recently.