I am new to Spring and I am currently using it in one of my projects. I learned that the Spring container holds all the beans and the scope of all the beans is "singleton"
by default. I can change the scope either in the application-context.xml
file or using the annotation @Scope
.
I furthermore learned that if a class has the scope "prototype"
, the Spring container will instantiate a new object of this class whenever needed.
What I don't understand: How is garbage collection handled. Will the created objects be garbage collected if they are no longer required or will they still be kept in the container. Obviously, I do not want many objects to be created and kept in order to keep memory usage low.