Android的AdMob的内存使用情况内存、情况、Android、AdMob

2023-09-08 18:52:26 作者:三分醒七分醉

我很困惑多少内存 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的广告,否则code几乎相同(使用普通的Andr​​oid 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的应用程序(安卓4.2.1)和比较内存使用情况。 我看用在设备设置>应用程序>运行应用程序的系统内存。 我也看Dalvik的堆内存所报告的GC logcat的消息,并使用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

在换句话说,达尔维克堆大小是相似的两个版本。 但实际的系统内存用的是 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的堆!

现在我想知道两件事情:

Now I'm wondering about two things:

我相信,既然免费版,系统内存为10MB大 比付费版本,它更容易被通过操作系统的情况下丧生 内存pressure。抑或是Android操作系统既兼顾 在Dalvik的堆决定哪些应用终止? 有没有办法调整AdMob的SDK来选择它有多少内存 允许分配? 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?

感谢的很多

推荐答案

AdMob的使用的WebView加载广告。这是一个相当复杂的对象,这使得利用本地库,并且很容易出现死机。在AdMob的SDK试图挺难以方便管理,但是你真的没有了它是如何工作的任何控制权。此外,内存使用情况可能会有所不同按广告类型:HTML文本的人VS横幅图像等。

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的(这不是开源的),你就必须忍受它。您可以删除和销毁 AD浏览报的主动,以减少任何泄漏,但没有更多可以做。

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.