Suspected memory leak

2019-05-04 19:31发布

I'm using Eclipse's Memory Analyzer to analyze a heap dump for my app, since I think I'm getting a memory leak somewhere. I'm not exactly sure what to look for, but the Leak Suspect report in MAT is showing 4 "problem suspects", which are:

 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. 

The last one I'm guessing is that I'm using too many Strings? The others I have no clue. I'm not using any encryption, so I don't know why BouncyCastle is showing.

The only code I can think of that is causing the "suspects" is this:

 final InputStream stream = new URL(feedUrl).openConnection().getInputStream();

 Xml.parse(stream, Xml.Encoding.UTF_8, root.getContentHandler());
 stream.close();

I'm parsing some remote XML files (using SAX), of varying sizes, but nothing over 1MB. This code is part of a loop that parses about 5-6 xml files.

Any insight as to what the "problems suspects" are, if they are causing a memory leak and a way to fix it, would be GREATLY appreciated.

2条回答
神经病院院长
2楼-- · 2019-05-04 19:43

The problem suspects are just that: the first place to look for memory leaks. They are the top uses of memory in your application by object type. It is quite possible that you don't have memory leaks, but you can try to reduce memory usage in general by looking at these objects first.

Here are some resources with more information

查看更多
你好瞎i
3楼-- · 2019-05-04 19:50

you're right: see and remove leaks - two different things. If there is an urgent need - with the help Deleaker you can find the leak, but it can be localized.

查看更多
登录 后发表回答