Question

Does Spring somehow optimize memory usage when using singleton beans which are lazily loaded?

Assume that we have as singleton bean which represents some module (application frame/ window) and it's lazy. This bean loads some classes which are components of this frame and which are not defined in Spring's IoC container.

Assume that we close the module JFrame, all components of frame should normally be garbage collected but they are still referenced by spring bean.

Does spring optimize memory usage in this situation?

To be precise I am not asking about prototypes but about singletons. Because we have strange behavior where using Spring singletons memory is released when closing the window. Even more memory is released when we use a prototype bean for the window.

Was it helpful?

Solution

Spring doesn't release singleton once it is instantiated. Releasing memory on window closing is probably consequence of some resource releasing which is done after windows closing, and probably doesn't have anything to do with Spring bean. For more information you should post some code, what is your bean, how window is opened and closed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top