Find a class that takes memory

I published the application a few months ago on Google Play, most of my users had serious problems with memory usage in my application, and this is true, because when I checked my memory usage on the "Launch application" tab, I see that it takes 80 ~ 110 MB of memory as shown below:

enter image description here

To find the class / activity or code fragments that cause this problem, I found a useful MAT plugin (Memory Analysis Tools), but it really confuses me, please consider the following image:

enter image description here

The total size of the used memory is 9.8 MB , however the "Launch Application" tab will show me 80 MB !

Another problem is the histogram, object Shallow heap of object byte[] too high.

This is normal? Also, when I debug some Google project, the byte value is always too big!

enter image description here

So how can I find that uses all this memory?

+1
java android memory-management memory-leaks
source share
2 answers

When an Android application starts, it inherits objects allocated by Zygote - a trick to speed up application development. Therefore, when you receive a memory dump, they are displayed as your own.

The answer to the question of why Zygote has such a memory allocation is another trick to speed up resource loading. During Android loading, Zygote preloads a list of classes and resources so that all other applications do not download them every time.

See ZygoteInit.java # 330 for this preload.

The heavy use of byte arrays is due to these preloaded resources (which are bitmap images).

See this answer for a more specific example of analyzing the use of a MAT / byte array from a specific resource.

+2
source share

Have you tried using visual vm ? Here is a good tutorial to learn about memory usage in classes and instances ( visual vm tutorial ). Hope this helps you.

0
source share

All Articles