Dilnoor Singh
Dilnoor Singh

Reputation: 518

Unexpected Heap Dumps for Hello World Android APP

I am learning about Memory Utilization using the MAT in Eclipse. Though I have ran into a strange problem. Leave aside the heavy apps, I began with the most benign The "Hello World" App. This is what I get as Heap Stats on Nexus 5, ART runtime, Lollipop 5.0.1.

ID: 1
Heap Size: 25.429 MB
Allocated: 15.257 MB
Free: 10.172 MB
% Used: 60%
# Objects: 43487

My Heap dump gives me 3 Memory Leak suspects: Overview

"Can't post the Pie Chart because of low reputation."

Problem Suspect 1

The class "android.content.res.Resources", loaded by "", occupies 10,166,936 (38.00%) bytes. The memory is accumulated in one instance of "android.util.LongSparseArray[]" loaded by "".

Keywords android.util.LongSparseArray[] android.content.res.Resources

Problem Suspect 2

209 instances of "android.graphics.NinePatch", loaded by "" occupy 5,679,088 (21.22%) bytes. These instances are referenced from one instance of "java.lang.Object[]", loaded by "" Keywords java.lang.Object[] android.graphics.NinePatch

Problem Suspect 3

8 instances of "java.lang.reflect.ArtMethod[]", loaded by "" occupy 3,630,376 (13.57%) bytes. Biggest instances: •java.lang.reflect.ArtMethod[62114] @ 0x70b19178 - 1,888,776 (7.06%) bytes. •java.lang.reflect.ArtMethod[21798] @ 0x706f5a78 - 782,800 (2.93%) bytes. •java.lang.reflect.ArtMethod[24079] @ 0x70a9db88 - 546,976 (2.04%) bytes. Keywords java.lang.reflect.ArtMethod[]

This is all by a simple code of:

import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

}

Questions

  1. Why are the heap numbers so big. ? Also as a side note the app was consuming 52 MB of RAM in the system.
  2. Where are these 209 instance of NinePatch coming ? I merely created the project by doing a "Create a new Project" in Eclipse ?
  3. The first leak suspect of resources, It comes up all the time in my analysis of apps. Is it really a suspect ?
  4. What is the ArtMethod? Does it have to do something with the ART runtime ?

Upvotes: 26

Views: 2486

Answers (2)

yadhu
yadhu

Reputation: 1323

In Lollipop the default runtime is ART i.e Android Run Time, which replaces the old Dalvik Run Time(DRT) used in older Android versions. In KitKat, Google released an experimental version of ART to get feedback from the users. In Dalvik JIT(just in time compilation) is used, which means when you open the application only then the DEX code is converted to object code. However, in ART the dex code is converted to object code(i.e AOT ahead of time compilation) during installation itself. The size of this object code is bigger compared to the DEX code therefore ART needs more RAM than DRT. The advantage of ART is that ART apps have better response time over DRT apps.

Upvotes: 6

Creati8e
Creati8e

Reputation: 21

Yesterday i'm faced with this problem too. In your log key word is "NinePatch". In my case the cause was a "fake" shadow - tiny picture with alpha channel which trigger resource leak. It's costs about 60mb leaked memory for me.

Upvotes: 0

Related Questions