0

I tried to analyze the memory consumption of my application. So I have a .hprof File. The crazy thing now is I get different results with pretty much every software.

I took a Sample Class where I compared all the values. Pretty much all numbers are equal except the Retained memory.

E.g. the Numbers for Retained memory in those tools:

  • Opening HPROF in Eclipse Memory Analyzer: 984
  • Eclipse Memory Analyzer on the Left Info: 456
  • Opening HPROF in Android Studio: 470
  • Reading the HPROF with Perflib from Google: 568

Why are there so big difference between those tools? Did anyone of you have similar experience?

Android Studio Footage: enter image description here

If i look into the details in Android Studio of the CommunicationManager class I get the following view and see that the Shadow$_klass has the same value (568) as Perflib. See here:

enter image description here

PerfLib Console Log:

The perflib Output shows the Number which gets returned by ClassObj when I call "getTotalRetainedSize()".

enter image description here

Eclipse Memory Analyzer: enter image description here

But on the left side in Eclipse Memory Analzyer I can see the following: enter image description here

Highriser
  • 212
  • 2
  • 14

1 Answers1

0

I know found out how I can get from the Perflib to the Values from Android Studio. Still I don't know what the Eclipse Analyzer does.

How do get Values from Android Studio:

  1. Get the ClassObj(s)
  2. Check the Hard References of this ClassObj and take all Hard References which are the same class as the ClassObj. Take that Instance and calculate the TotalRetainedSize and Sum those up if there are more.
  3. If there is no Hard Reference use the Shallow Size as Retained Size.

Code:

for(int i = 0; i < listOfClassObj.size(); i++){
   ClassObj clazz = listOfClassObj.get(i);
   ArrayList<Instance> list = clazz.getHardReferences();

   long retainedValue = 0;

   if(list.size() > 0){
       for(int x = 0; x < list.size(); x++){
           Instance inst = list.get(x);
           String instanceStr = inst.toString();
           if(instanceStr.substring(0, instanceStr.indexOf("@")).contentEquals(clazz.getClassName())){
               retainedValue += inst.getTotalRetainedSize();
           }
       }
   }else{
       retainedValue  = clazz.getShallowSize();
   }
}
Highriser
  • 212
  • 2
  • 14