Potential memory leak of bitmap reported by heap analysis tools but no bitmaps used by App

868 views Asked by At

My App is running fine (i.e. no crashes). During testing I have been investigating memory use. I use Android Studio (AI-141.2006197) DDMS to output a Dump HPROF file then open it in the Eclipse Memory Analyzer. This tool describes a leak suspect:

One instance of "android.graphics.Bitmap" loaded by "<system class loader>" occupies 
2,536,984 (40.81%) bytes. The memory is accumulated in one instance of "byte[]" 
loaded by "<system class loader>".

Keywords
byte[]
android.graphics.Bitmap

Some more information from the dominator_tree:

path2gc

Over the last day I have stripped the opening activity and fragment of my App to bare bones, removing all opening and reference to bitmaps, removing menus, service, everything. All that's left is one activity containing 1 fragment. The fragment has a ListView, with each list item having a simple TextView. No bitmaps are used. I can show the code in a later edit to this question if needed.

I am testing this stripped-down App on a phone and a tablet. I install the App, start it, see the list displayed by the first fragment, then exit. Via DDMS I cause a GC then do the heap dump and examine it in the Eclipse memory Analyzer. For both the phone and the tablet I see the "potential" memory leak.

My test phone, which uses a cynogenmod ROM, has a performance setting option to "Allow Purging of Assets" (see http://pocketnow.com/2012/12/10/5-nexus-4-speed-tips#toc-5). When I enable this feature my potential memory leak disappears. This makes me think there isn't a problem with my App after all, but its some system behaviour that I don't understand.

Some questions:

  1. Is this likely a memory leak in my App?
  2. If my test App is not using bitmaps or drawables, why is memory for a bitmap be allocated? What can I check?
  3. Do you have any words of wisdom regarding interpreting which potential memory leaks reported by the Eclipse memory Analyzer can be ignored?

Thanks in advance. I come from an embedded real-time C background so get very nervous when I see memory leaks!

2

There are 2 answers

0
pbm On BEST ANSWER

This bitmap is system-related and not a memory leak in the App. I came to this conclusion via posts Android EdgeEffect appears to allocate a 1 meg bitmap and Strange Bitmap using 1 Mb of Heap.

For anyone reading this I'd like to bring to your attention another very useful post that showed me how to view the bitmaps that are pointed to by the Eclipse Memory Analyzer tool. This can really help with debugging. See MAT (Eclipse Memory Analyzer) - how to view bitmaps from memory dump

0
tachyonflux On

All views generate bitmaps caches of themselves. This is likely a memory leak. It seems to occur when there are frequent layout changes on the view. You could try to disable the cache to see if it resolves your issue:

view.setDrawingCacheEnabled(false);