JAXBContext.newInstance memory leak

10,130

Solution 1

Which implementation & version of JAXB are you using? If you are using the reference implementation that comes with Java SE 6, then it is Metro (https://jaxb.dev.java.net/).

Here are some of there memory related bugs:

If you happen to be using the MOXy implementation (http://www.eclipse.org/eclipselink/moxy.php) then I can help debug.

The good news is that JAXBContext is thread-safe and should only be created once and re-used. Reusing the JAXBContext also appears to be solving your memory leak.

For more information see:

Solution 2

Yes, it's a leak. It will load the class “ruby.oracle_servlet.schemas”, every time this method is called.

JAXBContext.newInstance(“ruby.oracle_servlet.schemas”)
Share:
10,130

Related videos on Youtube

Lissy
Author by

Lissy

Updated on May 01, 2022

Comments

  • Lissy
    Lissy almost 2 years

    After a recent deployment in system test, one of our servlets was getting hit much harder than usual and we noticed memory started climbing and weblogic would eventually die. My intern, I was very proud, discovered the source of the memory leak.

    Whenever a request comes in, this line gets called:

    JAXBContext jc = JAXBContext.newInstance(“ruby.oracle_servlet.schemas”);
    

    For some reason, the object never gets garbage collected. Once we made it static and moved where we initialized it, our memory leak went away.

    Another one of our developers put just that line in a while loop in standalone java application and also saw the memory creep up and up.

    Does anyone have any ideas why that object doesn't get garbage collected?

    Thanks

  • bdoughan
    bdoughan almost 12 years
    @ThangPham - Thanks, I've updated my answer with the new link you have provided.
  • Kenogu Labz
    Kenogu Labz over 10 years
    Is this also a known issue with the release of JAXB for Java 7? The solution you gave would still hold, but it would be good to know if this is still something to watch for actively.
  • rogerdpack
    rogerdpack over 9 years
    does jaxb allocate any native memory when newInstance is called (outside of JVM land?)