本文介绍了Android内存泄漏,EMA怀疑:"byte []"由“<系统类加载器>"加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个小型的单活动android应用程序,但遇到内存泄漏错误,因为我找不到原点.首先,该应用程序计算基本内容并以结构化方式显示结果.计算很简单,尽管有一些图像,但它们大约有50个图标,总共不到4MB.

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.

我已经安装了Eclipse Memory Analyzer,并用它检查了堆转储,泄漏可疑报告说:

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

问题可疑1:477个"byte []"实例,由<系统类加载器>占用78.116.240(76.46%)字节.

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

dominator_tree

dominator_tree

我既不知道这些字节数组可能是什么,也看不到GC根目录或其他内容,因为这些数组在统治者树中没有父级.我并不经常为Android编程,而我拼命地试图弄清楚从今天开始这里发生了什么.当我使用该应用程序并观察在ADM中使用的堆大小/%时,我会从80%的使用率开始,然后随我的使用而变大. (还显示了1个字节的数组(byte [],boolean [])),直到应用在AVD上崩溃为止,我的真实设备可以将其处理更长的时间.我知道我可以增大尺寸,但这对我来说不是解决方案,因为我认为从一开始我就遇到了这个问题,现在它已经达到临界点.

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.

推荐答案

转到直方图视图:直方图"视图显示可按实例数量,浅堆(所有实例使用的总内存量)排​​序的类列表. )或保留的堆(所有实例(包括它们引用的其他对象)保持活动的内存总量.

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).

右键单击byte []类,然后选择带有传入引用的List Objects>.这样会生成堆中所有字节数组的列表,您可以根据浅堆使用情况对其进行排序.

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

侧注从Android 3.0(Honeycomb)开始,Bitmap对象的像素数据存储在字节数组中(以前它没有存储在Dalvik堆中)

SIDE NOTEAs 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)

这篇关于Android内存泄漏,EMA怀疑:"byte []"由“&lt;系统类加载器&gt;"加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 02:19