【发布时间】:2011-12-28 07:35:16
【问题描述】:
我正在使用 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 文件的循环的一部分。
任何关于“问题嫌疑人”是什么的见解,如果它们导致内存泄漏以及修复它的方法,将不胜感激。
【问题讨论】:
标签: android memory-leaks memory-management