Announcement Announcement Module
Collapse
No announcement yet.
Loading multiple application context has a memory leak? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Loading multiple application context has a memory leak?

    We have a testing framework that is loading a new spring application context for each test configured. (There are some technical reasons why we do not want to use the same application context to run all the tests).

    After running each test we are careful to make sure to close() the entity manager factory and the entity manager and null out the application context, so everything can be gc.
    We are seeing that after running a bunch of test we are running out of memory.
    We have done a heap dump and see that there is a problem with cglib.
    We have checked that in the past there have been reports of memory leaks related to cglib but the posts point out that all of them have been resolved?
    The version that we are using are:
    cglib - 2.1_3
    spring - 2.5.6
    Any help will be greatly appreciated.

  • #2
    Although I wouldn't advice you to do what you do (you don't really reload your whole application for each method invocation in your real application do you?).

    Close the applicationcontext instead of only closing the entitymanagers. Spring will then take care of the rest. If you have some timers or something else in there that will remain open en the context will not be gc'ed.

    Also if you use commons-logging that might also be a culprit and is known for its memory leaks (as well as cglib).

    Comment


    • #3
      Thanks for your reply, yes I agree that you do not create application context per function call, as I mentioned this was done for a specific technical reason that it came up when we were working on at test framework for our application.

      You mention to close the application context, but I am not sure on how to do this explicitly, there is no close() defined in the interface. It is defined in ConfigurableApplicationContext, but this is a subinterface of ApplicationContext and should be used only by SPI?

      Comment


      • #4
        In general yes, but y ou are already doing things which you really shouldn't be doing . So putting a simple cast in there and call close shouldn't be that hard.

        Comment

        Working...
        X