Interstitial ad does not release memory ever

656 views
Skip to first unread message

ees...@gmail.com

unread,
Mar 7, 2016, 4:45:59 PM3/7/16
to Google Mobile Ads SDK Developers
Hi,

I've integrated admob with mediation (FAN) in my app. While functionally, everything works great and I see ads being served as expected, I do not see memory ever being released by the interstitial - every time an ad loads, memory usage goes up by about 20MB and never goes down after that and the app finally crashes.

SDK Version : 7.7.0 XCode:7.2

To debug, I created this example which keeps loading a new interstitial every time I dismiss the ad (please note, this is just an example. In my app, the user actually plays at a new level before being presented with a new ad).

As you can see from this test code, I'm not really doing anything in the view controller except load the ad - I'm at a total loss as to how to proceed from here, appreciate any help in debugging this further!



#import "ViewController.h"


@interface ViewController ()


@end


@implementation ViewController


- (void)viewDidLoad {

[super viewDidLoad];

self.interstitial = [self createAndLoadInterstitial];

}

-(void)viewDidAppear:(BOOL)animated

{

[self showAd];

}

-(void)showAd{

if([self.interstitial isReady]){

[self.interstitial presentFromRootViewController:self];

}

else{

[self performSelector:@selector(showAd) withObject:nil afterDelay:2];

}

}

- (GADInterstitial *)createAndLoadInterstitial {


GADInterstitial *interstitial =

[[GADInterstitial alloc] initWithAdUnitID:@"MyAdUnit"];

interstitial.delegate = self;

GADRequest* __weak request = [GADRequest request];


// Requests test ads on test devices.


[interstitial loadRequest:request];

return interstitial;

}

// Called when an interstitial ad request succeeded.

- (void)interstitialDidReceiveAd:(GADInterstitial *)ad {


NSLog(@"interstitialDidReceiveAd");

}


/// Called when an interstitial ad request failed.

- (void)interstitial:(GADInterstitial *)ad

didFailToReceiveAdWithError:(GADRequestError *)error {

self.interstitial.delegate = nil;

self.interstitial = [self createAndLoadInterstitial];

[self showAd];


NSLog(@"interstitial:didFailToReceiveAdWithError: %@", [error localizedDescription]);

}


/// Called just before presenting an interstitial.

- (void)interstitialWillPresentScreen:(GADInterstitial *)ad {

NSLog(@"interstitialWillPresentScreen");

}


/// Called before the interstitial is to be animated off the screen.

- (void)interstitialWillDismissScreen:(GADInterstitial *)ad {

NSLog(@"interstitialWillDismissScreen");

}


- (void)interstitialDidDismissScreen:(GADInterstitial *)ad {

self.interstitial.delegate = nil;

self.interstitial = [self createAndLoadInterstitial];

[self showAd];


}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}


@end

Screen Shot 2016-03-07 at 1.40.35 PM.png

Veer Arjun Busani

unread,
Mar 7, 2016, 5:22:43 PM3/7/16
to Google Mobile Ads SDK Developers
Hi there,

I have just tested using our sample app with FAN integrated and found that the maximum memory usage is around 29MB. Now, this is considered to be normal as most of the transient memory is indeed deallocated once the Interstitial ad closes. The GADInterstitial object, in your case, would be reassigned, as you are trying to load a new Interstitial as soon as the previous one is closed. In any case the total memory used has not gone beyond 30MB and I would suggest you to try using our sample app to profile. Also try to test on an actual device.

Thanks,
Veer Busani
Mobile Ads SDK Team

ees...@gmail.com

unread,
Mar 7, 2016, 6:03:57 PM3/7/16
to Google Mobile Ads SDK Developers
Hi Veer,

Thanks much for the quick response. I just profiled with the sample app project and am running it on an actual device - IPhone 6 Plus (ios 9.0.2).

I still see a highly elevated memory usage. Attached both xcode memory stats and instruments allocations snapshot. Also note that leaks are highlighted - I just clicked on the "Play Again" button 3-4 times back and forth.

Not sure why I see such a drastically different experience - please let me know if you need any more info for repro/ have any suggestions for me?

Thanks.
Screen Shot 2016-03-07 at 2.59.46 PM.png
Screen Shot 2016-03-07 at 2.59.32 PM.png

Veer Arjun Busani

unread,
Mar 8, 2016, 9:58:38 AM3/8/16
to Google Mobile Ads SDK Developers
Hi there,

What's interesting about your snapshot of the Instruments is that there is a memory pointer to a StoreKit framework object. As I have suggested, please try to profile using our sample app. Also the SDK internally does clean up all of the resources without having any retain or strong reference to any unwanted objects. This does not mean that the iOS device would dealloc them immediately. It would still remain as transient and only gets dumped when it deems necessary. Given the fact that you might want to reload a new ad once the old one is closed, the iOS system might hold on to those objects if needed again in the future. Now here is the critical point, while profiling you need to look at these two factors - 
  • First would be to see if these transient memory objects are increasing in size. This would mean that there might be an issue as the iOS system is unable to dealloc the old ones properly.
  • Secondly, If it comes to a point where the device does need extra memory, the iOS system would flush out all of the unnecessary ones, including if any objects still being held for our Mobile Ads SDK. This way the device would always have sufficient memory unless something fishy is going on. Here you need to look at any objects piling up in memory and see if its coming from our SDK or not.
Considering this, I have noticed that the Mobile Ads SDK does not cause any increase in memory over time. It's also imperative to note that as the ads are being served over a WebView, taking 20-30 MB of memory is pretty normal usage.

ees...@gmail.com

unread,
Mar 8, 2016, 11:04:55 AM3/8/16
to Google Mobile Ads SDK Developers
Thanks Veer.

I was surprised at the Storekit traces as well, this is the sample app indeed!

I went back and experimented with the sample app using the ad unit id the code originally had - and I can no longer repro the consistent memory growth.

When I replace it with an ad unit id that allows text, image and video is when I see the memory issue - AVPlayer, AVAssetTrack, AVutableComposition and all other video/audio related objects seem left out on the floor even after the video closes at that point.

Agree that everything does get cleared up when a high memory warning is received, however given my app does spike in memory intermittently as well in combination to a possible memory leak in the video ads feels like a recipe for a crash.

Thanks.

Veer Arjun Busani

unread,
Mar 8, 2016, 12:26:49 PM3/8/16
to Google Mobile Ads SDK Developers
Hi there,

Like I said, all of these objects would be transient and even if they remain in memory, they would be flushed when needed. What you need to look at is the Persistent Bytes and even in your example, it's only at 2.97MB. See if your app is crashing due to this. I have also relayed the profile logs to our team.
Reply all
Reply to author
Forward
0 new messages