2

My setup:

There's a UITabBarController. In the first tab - there's a UINavigationController with a UITableViewController as a root viewcontroller.

In the table of UITableViewController, one of the cells contains a GADBannerView

In the cell with the bannerView, I'm loading the ad like this:

    var bannerView: GADBannerView = GADBannerView()
    ......
    bannerView?.adUnitID = "<my adUnitId>"
    bannerView?.adSize = kGADAdSizeMediumRectangle

    let request = GADRequest()
    request.contentURL = "<my site>"
    bannerView?.load(request)

Problem:

I've noticed, that if the ad contains the video/animation - after switching between tabs - the CPU usage is still high and remains on 15-20% load forever (until you kill the app).

Actual ad looks like this:

enter image description here

A couple observations:

  • if instead of the video-ad - there's a static-image-ad - there's no issue. To me this issue looks like there's some "pause animation" which is not being called for the video-ads.
  • happens on both iOS11 and iOS12
  • func adViewDidReceiveAd(_ bannerView: GADBannerView) is not being called, i.e. the framework knows that the ad is no longer on the screen

This is how processes look like (after switching to another, ad-free tab): enter image description here

Version of the AdMob:

'Firebase/AdMob', '~>5.15.0' (from cocoapods)

Any suggestions are very welcomed.

Konstantin Loginov
  • 15,802
  • 5
  • 58
  • 95
  • UITabBarController keeps the root UIViewControllers associated with its tabs alive in RAM after they have been instantiated even when you switch away to a different tab. If the ads in you UITableView are actually too RAM hungry to be kept alive, you're likely going to need to clean them up yourself when users switch away from the tab. – Dare Jan 03 '19 at 16:31
  • Thanks for the input, @Dare . I did `removeFromSuperview` on the banner and nil the reference afterwards on `viewWillDisappear` - it's keep the CPU high (any better ways to _clean up_?) . Plus, what bugs me - the refresh stops working - so the framework is kind of know that ad shouldn't be on the screen.. – Konstantin Loginov Jan 03 '19 at 16:42
  • Are you calling destroy() on both banner and interstitial ads? – Dare Jan 03 '19 at 16:48
  • @Dare I very well can be just stupid - but I don't see anything similar to destroy() (or synonyms) for `GADBannerView` class? (I've also set to `nil` both `rootViewController` and `delegate` for the banner - still same 16% CPU load) – Konstantin Loginov Jan 03 '19 at 17:02
  • Hi Konstantin, I encountered similar problem of high CPU load when loading native video ads, even when the cell is off screen, with latest GMA SDK. Have you fixed this issue? – Allen Hsu Nov 05 '19 at 11:58
  • @AllenHsu hey Allen. I wouldn't say that I've exactly _fixed_ it - rather just updated cocoapods couple of times and waited for the issue to go away. From my observations over the last 2-3 years with AdMob - this is the most legit strategy. – Konstantin Loginov Nov 07 '19 at 21:48
  • @KonstantinLoginov : Is it possible display different Ads on each recurring items? – Priya Jun 22 '20 at 01:20

1 Answers1

0

I faced the same problem and solved it by removing the banner every time the ad goes off screen add (re-) add it if it's visible again. This might happen in three cases:

  1. Cell is scrolled out of the visible area. Implemented in:

tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath)

  1. Navigate to subview. Implemented in:

viewWillDisappear

  1. App goes to background Add observer for appDidEnterBackground
Patrick_K
  • 219
  • 2
  • 11