Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
477 views
in Technique[技术] by (71.8m points)

java - 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 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...