Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS AdMob memory leak?

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]];
like image 549
Lorenzo Ang Avatar asked Nov 23 '22 14:11

Lorenzo Ang


1 Answers

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 ];
}
like image 157
Chrstpsln Avatar answered Dec 17 '22 02:12

Chrstpsln