Announcement Announcement Module
No announcement yet.
IOC + Heap Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • IOC + Heap

    HI all
    as we know that spring is eager instantiation ,so all the beans which we defined in xml file are avalibale as soon as application is deployed.but the heap memory size limited,so if all the spring instantiation beans resides in heap memory there would be problem,so how this problem is solved by spring.

  • #2
    There's only a problem if the maximum available memory is less than you're going to allocate with the set of beans defined in your context. This is essentially no different from any other application or framework. If you try to allocate more memory than you have, then it breaks.

    Also note that Spring's behavior of creating everything on startup is only the default. Read the "Lazy-initialized beans" section in the Spring doc for more information about this.


    • #3
      IOC + Heap

      Thanks for your reply and I gone through the spring docs.your reply was really helpful


      • #4
        I will add that the eager instantiation up front is a huge benefit to the Heap/memory management/Garbage Collection.

        1) Your long lived objects - beans that are stateless are instantiated first and therefore get into the tenured space quicker and stay there.

        2) Only one instance of those objects exists, - singleton scope. So this means I don't have 100s, 1000s of my services get created all the time causing lots of mark and sweep garbage collection, and leading to more stop-the-world garbage collections.

        3) If you lazy initialize, but still keep them as singletons are ok, but you will find that you will get a mix of short live and long live objects in your tenure space, which in the end might cause a few more stop-the-world garbage collections that you would have had eager loading them. (this is not 100% true all the time, but can happen)