I'm confused about how much memory AdMob SDK seem to be using, and where this memory is actually located. Let me explain.
I've got two flavors of my app: Free and Paid. Free version has AdMob ads, otherwise the code is almost the same (common Android lib used).
I run the apps on my Nexus 4 (Android 4.2.1) and compare memory usage. I look at system memory used by the app in device settings > apps > running. I also look at the Dalvik heap memory as reported by GC logcat messages, and using HPROF files.
When I run Paid version I can see:
- System memory: About 16MB
- Dalvik heap size: About 10MB
When I run the Free version I can see:
- System memory: About 29MB
- Dalvik heap size: About 11MB
In other words, the dalvik heap size is similar for both versions. But the actual system memory used is 10MB+ higher!
Having spent time learning about memory profiling (http://www.youtube.com/watch?feature=player_embedded&v=_CruQY55HOk), and hours looking at HPROF files to remove any possible leak, I can only see only one conclusion:
The 10MB extra system memory used by AdMob is actually native memory, allocated using malloc, outside of dalvik heap!
Now I'm wondering about two things:
- I believe that since Free version system memory is 10MB bigger than Paid version, it is much more prone to be killed by OS in case of memory pressure. Or does the Android OS only take into account the Dalvik heap for deciding which app to kill?
- Is there a way to tune AdMob SDK to select how much memory it is allowed to allocate?
Thank's a lot