tags:

views:

81

answers:

1

If I have a main appCtx and then I have a series of separate appCtxs which refer to the main one as the parent, then can I destory the child contexts to free up memory?

In effect I want to use the child appCtxs as object caches and I want to have the option of saying to a specific cache - "I'm not using the beans in this cache any more so I want to free up memory by invoking appCtx.close()"

I have tried prototyping this but I am not sure if the bean references in the child contexts are actually being removed - in other words, after close() are the beans available for garbage collection?

I realise this is a different way of using Spring, but my app is different and I have exhausted all other possibilities (custom scopes, SingletonBeanFactoryLocator, etc).

+2  A: 

Yes, invoking close() will release all resources. Beans will become eligible for garbage collection provided there are no other references to them.

ChssPly76