问题描述
我对 AdMob SDK 似乎使用了多少内存以及这些内存的实际位置感到困惑.让我解释一下.
I'm confused about how much memory AdMob SDK seem to be using, and where this memory is actually located. Let me explain.
我的应用有两种风格:免费和付费.免费版有 AdMob 广告,其他的代码都差不多(常用的 Android lib).
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).
我在 Nexus 4 (Android 4.2.1) 上运行应用程序并比较内存使用情况.我在设备设置 > 应用程序 > 运行中查看应用程序使用的系统内存.我还查看了 GC logcat 消息报告的 Dalvik 堆内存,并使用了 HPROF 文件.
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:
- 系统内存:约16MB
- Dalvik 堆大小:约 10MB
当我运行免费版时,我可以看到:
When I run the Free version I can see:
- 系统内存:约29MB
- Dalvik 堆大小:约 11MB
换句话说,两个版本的 dalvik 堆大小相似.但是实际使用的系统内存要10MB+以上!
In other words, the dalvik heap size is similar for both versions. But the actual system memory used is 10MB+ higher!
花时间学习内存分析(http://www.youtube.com/watch?feature=player_embedded&v=_CruQY55HOk),以及数小时查看 HPROF 文件以消除任何可能的泄漏,我只能看到一个结论:
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:
AdMob 使用的 10MB 额外系统内存实际上是本机内存,使用 malloc 在 dalvik 堆之外分配!
现在我想知道两件事:
- 我相信因为免费版系统内存要大 10MB比付费版更容易被操作系统杀死,以防万一的记忆压力.还是Android操作系统只考虑用于决定杀死哪个应用的 Dalvik 堆?
- 有没有办法调整 AdMob SDK 以选择它的内存量允许分配?
非常感谢
推荐答案
AdMob 使用 WebView 加载广告.这是一个相当复杂的对象,它使用本地库,并且容易崩溃.AdMob SDK 非常努力地使其易于管理,但您无法真正控制它的工作方式.此外,内存使用量可能会因广告类型而异:HTML 文本与带有图像的横幅等.
AdMob uses a WebView to load ads. That is quite a complex object which makes use of native libraries, and is prone to crashes. The AdMob SDK tries quite hard to make it manageable, but you don't really have any control over how it works. Additionally, memory usage will probably vary by ad type: HTML text ones vs banners with images, etc.
因此,除非您愿意对 AdMob 进行二进制修补(它不是开源的),否则您只能忍受它.您可以主动删除和销毁 AdView
以减少任何泄漏,但您无能为力.
So, unless you are willing to binary-patch AdMob (it's not open source), you just have to live with it. You can remove and destroy AdView
's proactively to reduce any leaks, but not much more you can do.
这篇关于Android AdMob 内存使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!