Java – Android memory leak, EMA suspected : “byte[]” loaded by “system class loader”

Android memory leak, EMA suspected : “byte[]” loaded by ““… here is a solution to the problem.

Android memory leak, EMA suspected : “byte[]” loaded by “

I’m writing a small single activity android app and getting a memory leak error because I can’t find the origin.
First, the app calculates the basics and displays the results in a structured manner. The calculation is simple, although there are some images, they have about 50 icons, for a total of less than 4MB.

I’ve installed Eclipse Memory Analyzer and checked heap dumps with it, and the Leak Suspects Report says

Question 1:
477 instances of “byte[]”, loaded by , occupying 78.116.240 (76,46%) bytes.


Dominating the tree

I neither know what those byte arrays might be, nor see the GC root or anything, because these arrays don’t have a parent in the dominance tree. I don’t program for Android very often, and I’m desperately trying to figure out what’s going on here from today. When I use the app and observe the heap size/percentage usage in ADM, I start directly with 80% usage and it gets larger as usage increases. (Also shows 1 byte array (byte[], boolean[])) Until the app crashes on the AVD, my real device can handle it longer.) I knew I could make the size bigger, but that wasn’t the solution for me because I thought I ran into this issue from the beginning and now it’s just reaching a tipping point.

Solution

Go to Histogram View: The histogram View shows that you can log by number of instances, shallow heap (the total amount of memory used by all instances), or reserved heap (by all instances, including other objects referenced by them).

Right-click the byte[] class and select List Objects > with incoming references. This generates a list of all byte arrays in the heap, which you can sort based on shallow heap usage.

Select a large object and drill down. This will show you the path from the root set to the object—the chain of references that keeps the object active. In the example below, bitmap caching is the culprit

enter image description here

Side bets
Starting with Android 3.0 (Honeycomb), the pixel data of Bitmap objects is stored in byte arrays (previously it was not stored in the Dalvik heap).

Related Problems and Solutions