iOS AdMob内存泄漏? [英] iOS AdMob memory leak?

查看:115
本文介绍了iOS AdMob内存泄漏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用 AdMob 但是我注意到,在运行了大约一个小时之后,它累积了50MB!让人惊讶。我想要释放它,但我不能,因为我使用 ARC 。有任何想法吗?我正在使用谷歌提供的入门代码:

I just started using AdMob but I noticed that, after running it for about an hour, it's accumulated 50MB! Yikes. I thought about releasing it but I can't since I am using ARC. Any ideas? I'm using the getting started code provided by google:

GADBannerView *bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];

CGRect newFrame = CGRectMake(self.scroller.frame.origin.x,self.scroller.frame.origin.y + 70,self.scroller.frame.size.width,self.scroller.frame.size.height);
[self.scroller setFrame:newFrame];

bannerView_.adUnitID = @"XXXXX";
bannerView_.rootViewController = self;

[bannerView_ setFrame:CGRectMake(0,
                                 20,
                                 bannerView_.bounds.size.width,
                                 bannerView_.bounds.size.height)];

[self.view addSubview:bannerView_];

[bannerView_ loadRequest:[GADRequest request]];


推荐答案

我遇到了同样的问题。

收到新广告后,您必须从父视图中删除之前的广告。

When receiving a new ad, you must remove the previous ad from the parent view.

否则,它们会叠加在一起并且消耗内存。

Otherwise, they are superimposed on each other and consumes memory.

因此,在收到超过15个广告后,分配的内存百分比保持不变。

So, after receiving more than 15 advertisements, the percentage of allocated memory remained constant.

希望这对你有帮助。

- ( void )displayBanner:( UIView * )banner
{    
    UIView * oldBanner = [ _bannerView viewWithTag:999 ];

    if( oldBanner )
    {
       [ oldBanner removeFromSuperview ];
       oldBanner = nil;
    }

    banner.tag = 999;
    [ _bannerView addSubview:banner ];
}

这篇关于iOS AdMob内存泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆