Finding and eliminating the causes of large heap sizes

I am trying to understand why my application uses so much memory. I often see that it uses from 15 to 18 MB, which is significantly higher than I expected. I looked at the heap size through DDMS and saw this:

enter image description here

It looked a little suspicious because my application does not deal with large images at all. In fact, the total amount of drawings in my application is about 250 KB. So I created a bunch of heaps and used MAT to determine where all this was happening. bytes [] were the biggest consumer, so I turned around and noticed the following:

enter image description here

I have absolutely no idea why sPreloadedDrawables is responsible for such a high heap size. I also do not know how to determine the root cause or how to fix it.

Where do I go next? My application works mainly in the background through services that do not deal with image data at all. I have actions that the user can use, but again they use small drawings that do not explain such a large heap size. I also checked for any unpleasant cases of activity leaks, etc., but did not find them.

EDIT: I noticed that the heap size is significantly lower when running in the emulator. This is pretty confusing.: /

+53
android memory-management ddms
Mar 11 '12 at 8:13
source share
1 answer

The system will preload the system resources by default, it does not depend on your application resources, such as standard Drawables for checkboxes and radio buttons. 10.5MB seems large, but there are many system resources by default, and the images are larger than ever stored in memory. Preloading is not new, but preloading may be larger in ICS. Display density probably plays a role in this along with just adding more system drawables preloaded into ICS.

There is currently no way to reduce the memory stored in sPreloadedDrawables

Unfortunately, there is no way to fix this after the application process is created for applications (especially games) that do not use most of the system Drawables. In this case, although the large size of the preload resources seems to have been a bug with a specific release (or phone port) of ICS. Otherwise, it is usually a small amount of memory, so I doubt that someday such a mechanism will be needed to reduce the use of pre-load memory.

If you run out of memory as a result of this cache, I will most likely write a bug report to Google.

Here you can follow the process of preloading resources if you are interested in more internal details. ZygoteInit.preloadResources

+44
Apr 04 '12 at 15:43
source share



All Articles