24

I'm using Swift language for ADMOB whenever new advertisement comes up, my Memory is increasing. I think there is a Leaking. Without ADMOB everything else is fine.

var inter: GADInterstitial
  override func viewWillAppear(animated: Bool) {
    inter = GADInterstitial()
    inter.delegate = self
    inter.adUnitID = "****"
    var request:GADRequest = GADRequest()
    request.testDevices = [ "***" ]
    inter.loadRequest(request)
}

And I'm using UIActionAlert for displaying the Interstitial

self.inter.presentFromRootViewController(self)

Memory Report Link:

https://www.dropbox.com/s/zjkt2f38rcy1ryr/Screenshot%202014-07-27%2020.17.18.png

Am I doing something wrong? I'm using ARC. Can I force to release this Interstitials by myself.

EDİT:

I tried GADBanner too. I'm just opening the app; I'm not doing anything else and memory is increasing

override func viewWillAppear(animated: Bool) {
 banner = GADBannerView()
 banner.delegate = self
 banner.adSize = kGADAdSizeSmartBannerPortrait
 banner.adUnitID = "****"
 var request:GADRequest = GADRequest()
 banner.rootViewController = self
 request.testDevices = [ "****" ]   
 self.view.addSubview(banner)
}

https://www.dropbox.com/s/3gn3pq3s1w2gfdd/Screenshot%202014-07-27%2022.05.51.png

  • 2
    I have the same problem with my App. Just starting the app and the memory fills up if the banner loads new ads. the same problem on my interstital ads, if i load a new one. it seems that the GADBannerView & GADInterstitalView never get cleaned up by ARC. It even stays on the same memory if I popToViewController. Anyone out there with a little trick? – zero3nna Aug 19 '14 at 18:16
  • Profile the app using the leak detector. Find out what object(s) is/are leaking and report back. – Daniel T. Oct 20 '14 at 02:14
  • Kerim, did you ever find a solution? – Minestrone-Soup Jun 15 '16 at 19:58
  • @Minestroni-Soup , I didn't find it but i think the best way is writing your implementation with changing the source code. Their codes had problems 2 years ago. – Kerim Doruk Akıncı Jun 17 '16 at 08:55
  • 4
    The leaking are still here in 2017 – Mike Keskinov Feb 07 '17 at 02:34

4 Answers4

3

You need to call destroy() to avoid memory leaks on both banner and interstitial ads. Interstitial ads are one-time-use objects, so you would have to destroy them. Banner ads can be reused but once done using them, call destroy().

See this for reference.

Pang
  • 9,564
  • 146
  • 81
  • 122
amigo_2627
  • 39
  • 3
1

I had the same issue, although with GADInterstitial AdMob ads. HUGE CPU churn from the memory leak. The problem is that you have to go to your actual root view controller. I'm in Objective C, but basically, if you're in, say, a UITabBarController view hierarchy, then try this:

banner.rootViewController = (UITabBarController *)self.view.window.rootViewController

That one thing solved all of my issues. Hope it works!

Mike Critchley
  • 1,643
  • 15
  • 20
0

I think you need to release the banner by setting delegate to nil. From AdMob documentation (see https://developers.google.com/mobile-ads-sdk/docs/admob/ios/banner?hl=es):

Note that if you implement your delegate as a distinct object rather than a GADBannerView subclass you should be sure to set the GADBannerView's' delegate property to nil before releasing the view.

- (void)dealloc {   
  bannerView_.delegate = nil;
   // Don't release the bannerView_ if you are using ARC in your project  
   [bannerView_ release];   
   [super dealloc]; 
  }

In your case I think you only need to implement the bannerView_.delegate = nil call.

I hope this helps.

Eva Madrazo
  • 4,731
  • 2
  • 23
  • 33
  • It may help, but I actually never releasing the view, this is the main view and an ads just eating all the memory, so in 10 minutes app crash because of memory issue. If disable ads, -- no leaks. So I know it's ads. – Mike Keskinov Feb 07 '17 at 02:39
0

I found that the best practice is to allocate the GADBannerView only once, otherwise it will pile up in your memory.

My solution is to store my GADBannerView in a singleton class, and allocate it when the app's rootViewController loads (didLoad). Then you can use it anywhere without requesting again.

piousLogic
  • 16
  • 2