Java应用程序中已加载类的数量可能发生内存泄漏 [英] Possible Memory leak in Number of Loaded classes in Java Application

查看:141
本文介绍了Java应用程序中已加载类的数量可能发生内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始分析我使用VisualVM编写的osgi java应用程序。我注意到的一件事是,当应用程序开始向客户端发送数据时(通过JMS),加载的类的数量开始以稳定的速率增加。然而,堆大小和PermGen大小保持不变。即使在停止发送数据之后,类的数量也永远不会下降。这是内存泄漏吗?我认为是,因为加载的类必须存储在某个地方,但是即使在我运行应用程序几个小时后,堆和permgen也不会增加。

I recently began profiling an osgi java application that I am writing using VisualVM. One thing I have noticed is that when the application starts sending data to a client (over JMS), the number of loaded classes starts increasing at a steady rate. The Heap size and the PermGen size remains constant, however. The number of classes never falls, even after it stops sending data. Is this a memory leak? I think it is, because the loaded classes have to be stored somewhere, however the heap and permgen never increase even after I run the application for several hours.

截图我的分析应用程序的此处

For the screenshot of my profiling application go here

推荐答案


你是否在某种程度上动态创建新类?

Are you dynamically creating new classes on the fly somehow?

感谢您的帮助。我弄清楚问题是什么。在我的一个类中,我使用Jaxb创建XML字符串。在这样做时,JAXB使用反射来创建一个新类。

Thanks for your help. I figured out what the problem is. In one of my classes, I was using Jaxb to create an XML string. In doing this, JAXB ueses reflection to create a new class.

JAXBContext context = JAXBContext.newInstance(this.getClass());

因此虽然JAXBContext没有在堆中说出来,但是这些类已被加载。

So although the JAXBContext wasn't saying around in the heap, the classes had been loaded.

我再次运行我的程序,我看到正常的高原,正如我所料。

I have run my program again, and I see a normal plateau as I would expect.

这篇关于Java应用程序中已加载类的数量可能发生内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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