gaurav
gaurav

Reputation: 3116

Spring ApplicationContext and BeanFactory

Spring Application Context will loads all Singleton beans at the time of Server StartUp . But in the case of big application , it has loaded many objects into memory .Won't it be the performance bottleneck in the application, Won't it gather the space on the Heap /permanent Space in the heap .

Upvotes: 1

Views: 964

Answers (2)

Bhaskar
Bhaskar

Reputation: 7523

It is a matter of design choice you as a programmer have to take - yes the objects will occupy memory - yes they are eagerly instantiated. How much memory these objects will occupy depends upon what they contain - it could be small or it could be huge. Whether its a good thing or bad depends on what your program does.

Just equally true is that Spring also supports lazy initialization of beans

<bean id="foo" class="com.foo.SomeBean" lazy-init="true"/>

Upvotes: 2

Ryan Stewart
Ryan Stewart

Reputation: 128849

No, this won't be what causes your memory problems, unless you're running on some embedded system with tiny memory space. "Many objects" in this context is maybe a few hundred or a few thousand at most. That adds up to virtually nothing with today's memory allocations.

Upvotes: 0

Related Questions