iAd & AdMob Heavy on Memory

2019-05-30 00:12发布

问题:

I've just completed coding my new game for the iOS platform and now I decided that it is time to integrate iAd/AdMob banners at the bottom of the screen. I have completed the implementation and an iAd is showing up and if it fails then it is replaced by an AdMob banner. This is great, however I checked over the memory consumption of the app and prior to iAd/AdMob integration, my app was running using around 19MB of memory - with the the iAd/AdMob integration, it is running using over 50MB of memory. I have two questions regarding this - are they supposed to be so memory-heavy like this or am I doing something wrong? Secondly, it seems as if these banner views are never getting released from memory. I have tried setting adBannerView = nil followed by [adBannerView removeFromSuperview] but still nothing happens and the memory does not lessen at all. F.Y.I - my game is ARC enabled.

Any help on this matter would be greatly appreciated! Thanks.

回答1:

The memory growth you are observing is a result of WebKits contribution to the heap. This unfortunate behavior has been the subject of a lot of outrage. You will find similar behavior if you try and load the banners using your own web views. There has also been similar discussions on SO like this one, and this one where developers have been locked in a futile war to attempt to reduce the memory impact of web loading.

I personally haven't used iAds yet but I am very familiar with Google Ad integration on iOS and we saw significant memory increases post-implementation.

TL;DR

That being said you should consider observing the debug memory gauge, simulate a memory warning, and then your usage should drop. In most scenarios I have encountered WebKit has done a decent job of removing its In-Memory cache.

However, If these memory warnings are not handled you should definitely seek to file a bug report.