JAXBContext.newInstance memory leak
After a recent deployment in system test, one of our servlets was getting hit much harder than usual and we noticed memory started climbing开发者_Python百科 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
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:
- https://jaxb.dev.java.net/issues/buglist.cgi?Submit+query=Submit+query&component=jaxb&email1=&emailtype1=exact&emailassigned_to1=1&email2=&emailtype2=exact&emailreporter2=1&issueidtype=include&issue_id=&changedin=&votes=&chfieldfrom=&chfieldto=Now&chfieldvalue=&short_desc=memory&short_desc_type=fulltext&long_desc=&long_desc_type=fulltext&issue_file_loc=&issue_file_loc_type=fulltext&status_whiteboard=&status_whiteboard_type=fulltext&keywords=&keywords_type=anytokens&field0-0-0=noop&type0-0-0=noop&value0-0-0=&cmdtype=doit&order=Reuse+same+sort+as+last+time
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:
- https://javaee.github.io/jaxb-v2/doc/user-guide/ch03.html#other-miscellaneous-topics-performance-and-thread-safety
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”)
精彩评论