0

I made some changes in my android service, like declared a hashmap of bitmaps as member variable, and populated it dynamically.

I am concerned that bitmaps might take up considerable RAM.

How can I confirm how much is the RAM usage increase after my changes. Is there any tool to check this ?

If anybody has worked in this area before, please help !

superuser
  • 625
  • 3
  • 7
  • 19
  • 2
    I think Eclipse offers some tools like this. Also, you can actually increase the heap size by adding android:largeHeap="true" to your manifest. It'll offer the absolute maximum heap size you can achieve with the SDK, if you want to determine your own heap size you have to use the NDK. – Tim Kranen Jan 17 '14 at 10:33
  • 2
    possible duplicate of [Detect application heap size in Android](http://stackoverflow.com/questions/2630158/detect-application-heap-size-in-android) – phemt.latd Jan 17 '14 at 10:46
  • To answer my own question, I found that capturing heap dump, and comparing the captured heap dumps taken at two different points, using a Memory Analyzer Tool (MAT), does the trick ! Please read about it on developer page - http://developer.android.com/tools/debugging/debugging-memory.html#HeapDump. – superuser Jan 27 '14 at 11:23

1 Answers1

1

there are eclipse android sdk tools to detect the current heap allocation size, but there is much simpler way to know current heap size:

just search in logcat for the words "Grow heap". every time the heap size of you application is grow - this log is printed to logcat, indicating also the current heap size.

it would look something like this:

02-22 11:20:57.040: I/dalvikvm-heap(5313): Grow heap (frag case) to 213.551MB for 3850256-byte allocation

generally, to avoid situation of too much bitmaps allocations, and to allocate bitmaps automatically on the scale type required for display, you should use library such Volley to handle for you the caching, and remote server fetching.

Volley mad by Google, and been use by the Google Play application for handling all requests in front of the server, and provides also smart ImageLoader that doing for you automatically the download,decode in correct sample size, displaying, memory cache and storage cache (if specified).

Tal Kanel
  • 10,475
  • 10
  • 60
  • 98
  • @ Tal Kanel: I could see "Grow heap" logs at the start of my service, but i could see no such logs, when dynamically bitmaps were created on press of some key. – superuser Jan 17 '14 at 11:05
  • @girlDevelopIt: when this log is not printed - it means that the heap size stayed the same – Tal Kanel Jan 17 '14 at 11:07
  • @ Tal Kanel: How can this be possible. I created new bitmap objects on press of key, and added it to my hashmap. As per my understanding it will go to heap only ? – superuser Jan 17 '14 at 11:09
  • 1
    ok. your assumption that heap size change every time allocation is been made is incorrect. when the application been created - a default heap size is given to it, and when the system detects your process is about to use this size - in one chank it grows to something like x2 , and so on – Tal Kanel Jan 17 '14 at 11:12
  • @ Tal Kanel: This means I will not be able to consider the heap allocated size to find out, how much memory loss my code change is creating. Or, maybe I can compare the heap-in-use size somehow. Or, the RAM size ? – superuser Jan 17 '14 at 11:18
  • 1
    @girlDevelopIt: I beleive that the growing heap size would reflect you memory usage in more clear way. after all - if the heap size stays the same - then it's pretty sure that you are "safe". if it's not enough for you - I'm suggesting you to read this- http://developer.android.com/training/articles/memory.html – Tal Kanel Jan 17 '14 at 11:25
  • 1
    @girlDevelopIt: this document describes how to monitor the exact heap size usage: http://developer.android.com/tools/debugging/ddms.html – Tal Kanel Jan 17 '14 at 11:35