如何使用Eclipse Memory Analyzer Tool(MAT)分析hashmap

sup*_*ser 5 java eclipse memory android android-memory

我正面临内存泄漏.所以,我heap dump为我的应用程序捕获了一个,并尝试使用Memory Analyzer Tool(MAT)进行分析.我点击菜单中的堆转储概览选项hprof file.然后,点击Class Histogram.它向我展示了按类分组的所有对象列表,它们占据了最大值.其中一个是我的cutom hashmap.现在,我想分析一下这个条目hashmap.

知道我怎么能这样做吗?如果我单击自定义散列映射名称,然后单击List Objects->with incoming references,它只显示hashmap创建这些对象的层次结构中的所有对象的列表,而不是散列映射条目的实际键值对.

PS我的自定义Hashmap:

private Hashmap<Integer, TextCache> mCache;

class TextCache{
    Bitmap bitmap;
    int left;
    int right;
    int keyCode;
}
Run Code Online (Sandbox Code Playgroud)

sup*_*ser 1

为了回答我自己的问题,我试图从Java/Debug透视图查看 hprof 文件。当我切换到透视图时,我可以在左侧的->窗口Memory Analysis中查看所有对象的详细信息,包括哈希映射条目的键值对。InspectorAttributes

编辑:哈希映射条目的“key”属性仍然不可见。只有我的自定义哈希图条目对象的属性(即“值”部分)可见。因此,出于测试目的,我所做的是将 key 属性(它是一个整数)放在自定义哈希映射条目对象中,以便能够从Inspector->Attributes的角度查看它Memory Analysis

class TextCache{
    Bitmap bitmap;
    int left;
    int right;
    int keyCode;
    int key; // this is actually the key used to insert objects of TextCache into the hashmap.
}
Run Code Online (Sandbox Code Playgroud)

如果有人知道如何直接查看 hprof 文件中的“关键”部分,那就太好了。