简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM