我正在使用Eclipse的内存分析器来分析我的应用程序的堆转储,因为我认为它存在内存泄漏。我不太确定要查找什么,但MAT中的泄露嫌疑报告显示了4个“问题嫌疑人”,它们是:
The class "org.apache.harmony.luni.internal.net.www.protocol.jar.JarURLConnectionImpl", loaded by "<system class loader>", occupies 608,976 (16.15%) bytes. The memory is accumulated in one instance of "java.util.jar.JarFile" loaded by "<system class loader>".
One instance of "org.apache.harmony.xml.ExpatParser" loaded by "<system class loader>" occupies 501,304 (13.29%) bytes. The memory is accumulated in one instance of "java.lang.Object[]" loaded by "<system class loader>".
127 instances of "org.bouncycastle.jce.provider.X509CertificateObject", loaded by "<system class loader>" occupy 451,280 (11.97%) bytes. These instances are referenced from one instance of "java.util.Hashtable$HashtableEntry[]", loaded by "<system class loader>"
6,608 instances of "java.lang.String", loaded by "<system class loader>" occupy 407,824 (10.81%) bytes.
我猜测最后一个问题可能是我使用了太多字符串?其他的我不知道。我没有使用任何加密,所以我不知道为什么会出现BouncyCastle。
我能想到唯一可能引起“嫌疑”的代码是这个:
final InputStream stream = new URL(feedUrl).openConnection().getInputStream();
Xml.parse(stream, Xml.Encoding.UTF_8, root.getContentHandler());
stream.close();
我正在解析一些远程XML文件(使用SAX),这些文件大小不同,但没有超过1MB。这段代码是循环中的一部分,用于解析大约5-6个XML文件。
如果它们导致内存泄漏并且需要修复它,请提供任何关于“问题嫌疑人”的见解,这将非常感激。