Android Memory Leak, EMA Suspect: “byte[]” loaded

2019-03-31 12:00发布

I'm writing a small single-activity android App and got a memory leak error, for wich I can't find the origin. First of all, the App calculates basic stuff and displays the results in a structured way. The calculations are trivial and although there are a few images, they are around 50 icons with less then 4MB total.

I already installed the Eclipse Memory Analyzer and checked a heap dump with it, the Leak Suspects Report says:

Problem Suspect 1: 477 instances of "byte[]", loaded by < system class loader> occupy 78.116.240 (76,46%) bytes.

dominator_tree

I neither know what those byte arrays could be, nor can I see the GC Roots or anything, because the arrays got no parents in the dominator tree. I don't often program for Android and I desperately tried to figure out, what's going on here since today. When I play around with the App and observe the Heap Size / %used in the ADM I straight start with 80% usage and get bigger as I go. (also shows 1-byte array (byte[], boolean[])) till the App crashes on the AVD, my real device can handle it a bit longer. I know I can make the size bigger, but that's no solution for me because I think I got this problem since the beginning and now it just reached the critical point.

1条回答
forever°为你锁心
2楼-- · 2019-03-31 12:55

Go to the histogram view: The Histogram view shows a list of classes sortable by the number of instances, the shallow heap (total amount of memory used by all instances), or the retained heap (total amount of memory kept alive by all instances, including other objects that they have references to).

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

Pick one of the big objects, and drill down on it. This will show you the path from the root set to the object -- the chain of references that keeps this object alive. In the case below the bitmap cache is the culprit

enter image description here

SIDE NOTE As of Android 3.0 (Honeycomb), the pixel data for Bitmap objects is stored in byte arrays (previously it was not stored in the Dalvik heap)

查看更多
登录 后发表回答