iOS app crashing with Admob (Memory Leak)

1,330 views
Skip to first unread message

Shravan Kumar Singireddy

unread,
Nov 1, 2016, 11:45:13 PM11/1/16
to Google Mobile Ads SDK Developers
Hello Google,

I have developed a Taboo word game app and is currently in the iOS app store.

I am working on the new version of the app which includes banner ads on pretty much every screen of the app.

But, after playing the game for some time (15 mins) the app crashes with the error "Message From Debugger: Terminated due to memory issue".

When i stop displaying ads the game works just fine even after playing for an hour.

Attached are the memory usage screenshots with and without the ads on the home screen of the app. As you could see the memory almost doubles when i display an ad. And the memory is never released even after i move to next screens. Eventually the app crashes after using up all the memory.

Here is my swift admob implementation code. 

    override func viewDidLoad() {

        super.viewDidLoad()

        configureGoogleAdBanner()

    }


    func configureGoogleAdBanner() {

        self.adBannerView.delegate = self

        self.adBannerView.isHidden = true

        self.adBannerView.adUnitID = HOME_ADUNIT_ID

        self.adBannerView.rootViewController = self

        let gadRequest = GADRequest()

        adBannerView.load(gadRequest)

    }

   

    func adViewDidReceiveAd(_ bannerView: GADBannerView!) {

        self.adBannerView.isHidden = false

    }


Here is my POD file 


# Uncomment this line to define a global platform for your project

source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '9.0'

use_frameworks!


target 'Taboo' do

pod 'Alamofire', '~> 4.0'

pod 'Firebase/Core'

pod 'Firebase/AdMob'


end


How can i release the memory used by the ads? I have tried a lot of options but nothing worked.


Please help me out. I cannot move forward with this issue.

WithAds.jpg
WithoutAds.jpg

Shravan Kumar Singireddy

unread,
Nov 1, 2016, 11:55:18 PM11/1/16
to Google Mobile Ads SDK Developers
BTW, i am running this app on an Actual device (iPhone 6 Plus) and not on a Simulator. The screenshots i provided are for the actual device

Xcode version: 8.1
iOS Version: 10.1.1 

Veer Arjun Busani(Mobile Ads SDK Team)

unread,
Nov 2, 2016, 10:27:32 AM11/2/16
to Google Mobile Ads SDK Developers
Hi Shravan,

Can you try to reproduce the crash with our sample apps? Looking at your memory usage, while using our SDK, I do not see any issue with whatsoever. A 10~15MB memory increase is certainly acceptable and may not be the cause of the crash. 

Can you run Instruments to get the actual picture of memory usage/leaks in your app? That might give the overall picture and what might be causing this issue in your app. If you are unable to get that, then either send us a minified version of your app (you can privately send us that) or the complete logs from Instruments.

Thanks,
Arjun Busani
Mobile Ads SDK Team

Shravan Kumar Singireddy

unread,
Nov 2, 2016, 7:37:47 PM11/2/16
to Google Mobile Ads SDK Developers
Hello Veer,

Thank you very much for your reply. I am ok with the 10-15 MB increase but, i think that memory is never getting released when i move on to the next screens.

Your sample app has just one screen with the ad. So, i don't think i would be able to replicate my issue on the sample app.

In my app the memory usage increases after navigating to multiple screens.

I can provide you a minified version of my app with just first 2 screens but, can you tell me how to send it privately?. 

Both screens load banner ads. The difference between this minified version and my original app is the usage of the navigational controller. In my original app i am not using the Navigation Controller (but, thinking of using it). But, with or without navigational controller i run into this memory issue

To replicate the issue just click the Start button on first screen and click the back button on the next screen. Do this back and forth multiple times and you would see that the memory increases drastically. 

I have attached another screenshot of the xcode memory usage for this minified app version when i did the back and forth for 10-15 times. If i do the same by commenting out the ad code and the memory stays constant at 21-22 MB.
MemoryUsage.jpg

Shravan Kumar Singireddy

unread,
Nov 2, 2016, 7:44:47 PM11/2/16
to Google Mobile Ads SDK Developers
Also, i am new to instruments debugging. But, i did take a look at it and found that my view controllers reference count was increasing by one every time that controller is displayed (the old instances are never getting killed - in this case i was using seques between controllers). That is when i decided to use the navigation controller  which was keeping the viewcontrollers reference count to always 1. I thought that would resolve the memory issue but, that did not solve it. I am not sure on how to look for other issues in Instruments

Veer Arjun Busani(Mobile Ads SDK Team)

unread,
Nov 3, 2016, 10:26:05 AM11/3/16
to Google Mobile Ads SDK Developers
Hi Shravan,

This sounds like an implementation issue. You can send your sample app by replying to me privately. If you are unable to, let me know and I will send you an email that you can respond to directly.

Thanks,
Arjun Busani
Mobile Ads SDK Team

Shravan Kumar Singireddy

unread,
Nov 3, 2016, 2:56:14 PM11/3/16
to Veer Arjun Busani(Mobile Ads SDK Team)' via Google Mobile Ads SDK Developers
Hello Veer,

Can you please send me an email to which i can respond with the code?

Thanks for your help.

Regards,
Shravan

--

---
You received this message because you are subscribed to a topic in the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-admob-ads-sdk/clcME6vdhWQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-admob-ads...@googlegroups.com.
To post to this group, send email to google-adm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Veer Arjun Busani(Mobile Ads SDK Team)

unread,
Nov 4, 2016, 9:21:17 AM11/4/16
to Google Mobile Ads SDK Developers
Hi Shravan,

I have not found anything wrong with your implementation. Here is my analysis on this -
  • Transient memory
    • The first thing to understand is that the memory being taken up is all Transient memory. Meaning that it would be flushed out by the system if the device is in need of it. What you need to be worried about is Persistent memory. 
    • The AdView is being held in reference because the system understands that the user can at anytime go back from B-ViewController to A-ViewController and so on. 
    • One way to manage this is by removing the AdView from the UIView when a new VC is being presented.
  • RootVC
    • One ideal way would be to have a RootViewController, such as a UINavigationController, and have one reference to the Banner AdView and place it in the rootVC. 
    • This way, you can have as many VC's being presented by the rootVC but will still have one reference to the BannerView.
  • Cause of your crash
    • I still believe that the root cause for your app's crash might be something else. 
    • It would be interesting if you can memory profile using Instruments as linked earlier to see whether the references at the time of the crash are pointing to our SDK or to your own apps. 
Thanks,
Arjun Busani
Mobile Ads SDK Team

On Thursday, November 3, 2016 at 2:56:14 PM UTC-4, Shravan Kumar Singireddy wrote:
Hello Veer,

Can you please send me an email to which i can respond with the code?

Thanks for your help.

Regards,
Shravan

To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.

Shravan Kumar Singireddy

unread,
Nov 4, 2016, 10:03:10 AM11/4/16
to Google Mobile Ads SDK Developers
Hello Veer,

Thank you for the analysis.

Few questions if you don't mind. Please answer with a yes or a no

1. Did you see the memory usage go high when you go back and forth between controllers with ads ON? This is just for me to know that i am reading it right

2. Did you see the memory usage stay constant when you go back and forth between controllers with ads OFF? This is also just for me to know that i am reading it right

3. Were you able to crash the minified app that i provided? It will definitely crash if i keep going back and forth

4. The memory that is being used when i go back and forth between controllers in the minified version - is that ALL Transient memory? none of it was persistent? In that case this minified version should neve crash right?

5. I can try this option you provided "One way to manage this is by removing the AdView from the UIView when a new VC is being presented." But, this would just help me save Transient memory and not persistent one right?

I did try a singleton ad BannerView earlier as you suggested but that did not help me. So, that leaves me to debug more with instruments which i need to learn more in depth :)

Again thanks for all your help Veer.

On Friday, November 4, 2016 at 9:21:17 AM UTC-4, Veer Arjun Busani(Mobile Ads SDK Team) wrote:
Hi Shravan,

I have not found anything wrong with your implementation. Here is my analysis on this -
  • Transient memory
    • The first thing to understand is that the memory being taken up is all Transient memory. Meaning that it would be flushed out by the system if the device is in need of it. What you need to be worried about is Persistent memory. 
    • The AdView is being held in reference because the system understands that the user can at anytime go back from B-ViewController to A-ViewController and so on. 
    • One way to manage this is by removing the AdView from the UIView when a new VC is being presented.
  • RootVC
    • One ideal way would be to have a RootViewController, such as a UINavigationController, and have one reference to the Banner AdView and place it in the rootVC. 
    • This way, you can have as many VC's being presented by the rootVC but will still have one reference to the BannerView.
  • Cause of your crash
    • I still believe that the root cause for your app's crash might be something else. 
    • It would be interesting if you can memory profile using Instruments as linked earlier to see whether the references at the time of the crash are pointing to our SDK or to your own apps. 
Thanks,
Arjun Busani
Mobile Ads SDK Team

On Thursday, November 3, 2016 at 2:56:14 PM UTC-4, Shravan Kumar Singireddy wrote:
Hello Veer,

Can you please send me an email to which i can respond with the code?

Thanks for your help.

Regards,
Shravan

To post to this group, send email to google-adm...@googlegroups.com.

Veer Arjun Busani(Mobile Ads SDK Team)

unread,
Nov 4, 2016, 12:03:08 PM11/4/16
to Google Mobile Ads SDK Developers
Hi Shravan,

1. Did you see the memory usage go high when you go back and forth between controllers with ads ON? This is just for me to know that i am reading it right
No. I found that the memory usage from going back and forth between the VC's to be consistent and no uneven spikes.
2. Did you see the memory usage stay constant when you go back and forth between controllers with ads OFF? This is also just for me to know that i am reading it right
Yes. Again, there were no memory spikes without the ads as well. Also, I didn't find anything unusual with your implementation. 
3. Were you able to crash the minified app that i provided? It will definitely crash if i keep going back and forth
No. Now this I was unable to reproduce. I have tried to do so while going back and forth as many as 20 times but failed to reproduce any crash. Can you try to with a different device maybe and see if you are still able to reproduce the issue.
5. I can try this option you provided "One way to manage this is by removing the AdView from the UIView when a new VC is being presented." But, this would just help me save Transient memory and not persistent one right?
As I have mentioned, if you try with the Instruments tool to memory profile the app, there would not be much persistent memory. You can try this method, but I would recommend the UINavigationController method and see if you can have one Banner View consistent for the entire app. 

Thanks,
Arjun Busani
Mobile Ads SDK Team

Reply all
Reply to author
Forward
0 new messages