简体   繁体   English

iOS AdMob内存泄漏?

[英]iOS AdMob memory leak?

I just started using AdMob but I noticed that, after running it for about an hour, it's accumulated 50MB! 我刚刚开始使用AdMob但我注意到,在运行了大约一个小时之后,它累积了50MB! Yikes. 让人惊讶。 I thought about releasing it but I can't since I am using ARC . 我想要释放它,但我不能,因为我使用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]];

I had the same problem. 我有同样的问题。

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. 否则,它们会相互叠加并消耗内存。

So, after receiving more than 15 advertisements, the percentage of allocated memory remained constant. 因此,在收到超过15个广告后,分配的内存百分比保持不变。

Hoping that this will help you. 希望这会对你有所帮助。

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

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM