iOS AdMob memory leak?

谁说胖子不能爱 提交于 2019-12-12 07:37:22

问题


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]];

回答1:


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.

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 ];
}


来源:https://stackoverflow.com/questions/25397119/ios-admob-memory-leak

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!