How to debug memory leak when exception instances in heap dump have no inbound links?

I am trying to diagnose a memory leak in the android application that I am writing. I got a bunch of heaps loaded in Eclipse, but the results that I see are very curious. There are about 20,000 exception instances (notably LDAPException from the LDAP UnboundID library) on the heap without inbound links.

That is, they appear in the root of the dominant tree. OQL SELECT objects e FROM com.unboundid.ldap.sdk.LDAPException e WHERE (inbounds(e).length = 0) returns more than 20,000 results, which corresponds to almost the entire heap. Nevertheless, GC works before the heap dump, and I see that it works on the console repeatedly during the execution of leaky code. If these instances do not have inbound links, what can support them?

I also tried to execute the "shortest paths to the GC" query. It shows one LDAPConnectionReader line that stores 2 instances, and ~ 20k LDAPException @ <addr> unknown lines with different hexadecimal addresses.

Update . I did not have time to continue to diagnose this, after publishing it, and the award I noted ends earlier than I probably will. I reward him as best as possible so that the glasses are not wasted. Thanks to everyone who looked into this! I will come back later and again clarify the results of a further diagnosis, when life will be a little less hectic.

+6
java android memory-leaks
source share
3 answers

Regardless of whether these Exceptions are thrown in terms of memory usage, this information is largely irrelevant.

As long as you want to see a heap on the heap that holds links, for some reason you cannot do this. I wonder if native code will be correctly displayed in the heap dump tool?

In any case, as something new, I would suggest not debugging the point at which these Exceptions are thrown, but where they are created. Put breakpoints on the class and / or all its constructors. Ideally, you simply get this information from the heap dump links, but it can still be informative if you can see who repeatedly constructs these objects ... I assume that they come from the same place.

+4
source share

If you use Eclipse, you can add a breakpoint on LDAPException . Here you can find a tutorial on how to install it: Eclipse tip: breakpoint on exception .

These breakpoints pause execution if an exception of the selected type is thrown. Once you know the conditions that cause so many exceptions, you can fix the error.

This is not really debugging, why thrown Exceptions populate the heap, but I hope this can help.

+1
source share

I am not familiar with OQL or, in particular, with the Android platform or the internal processing of Java GC on this platform, but the most obvious for me is the lack of LDAPException metadata. He received error codes, messages, methods, etc .... where is it? Was it uninitialized? Can't you post it all? Something like redirecting the server to itself can make me say, "Oh, this is strange, but it made sense."

Have you tried replacing this lib with JDK one ? It seems like it should be easy if possible.

Then I would start to squeeze a bunch for everything that she did. GC specifications can be the key. Are there instances that somehow obscure the collection? How much is created per second? What part of the obsolete gc'd goes through each pass, or is it a constant amount? Are they created in the closed loop that Danny talked about? What if you call System.gc() in a busy loop?

But yes, when I start debugging prints. Hope there is a better solution. :-P

+1
source share

All Articles