JAXBContext.newInstance 内存泄漏 [英] JAXBContext.newInstance memory leak

查看:77
本文介绍了JAXBContext.newInstance 内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在最近的系统测试部署之后,我们的一个 servlet 受到的打击比平时大得多,我们注意到内存开始攀升,而 weblogic 最终会死掉.我的实习生,我很自豪,发现了内存泄漏的来源.

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.

我们的另一位开发人员将该行放在独立 Java 应用程序的 while 循环中,并且也看到内存不断增加.

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?

谢谢

推荐答案

哪个实现&您使用的是 JAXB 版本吗?如果您使用的是 Java SE 6 附带的参考实现,那么它是 Metro (https://jaxb.dev.java.net/).

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:

如果您碰巧使用 MOXy 实现(http://www.eclipse.org/eclipselink/moxy.php) 然后我可以帮忙调试.

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

好消息是 JAXBContext 是线程安全的,应该只创建一次并重复使用.重用 JAXBContext 似乎也解决了内存泄漏问题.

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:

这篇关于JAXBContext.newInstance 内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆