Paul Drummond
Paul Drummond

Reputation: 295

Using Multiple ApplicationContexts in Spring - question about cleaning up resources

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).

Upvotes: 0

Views: 492

Answers (1)

ChssPly76
ChssPly76

Reputation: 100726

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

Upvotes: 2

Related Questions