after loading InterstitialAd.load with InterstitialAdLoadCallback I have a memory leak

219 views
Skip to first unread message

You Loulou

unread,
May 8, 2023, 7:02:36 PM5/8/23
to Google Mobile Ads SDK Developers
after loading InterstitialAd.load with InterstitialAdLoadCallback I have a memory leak
I call the finish() function in Activity which uses the InterstitialAd announcements but the garbage collector I do not recover the activity because call back from InterstitialAd is currently using the activity.
I have a memory leak on all the Activities that call loading InterstitialAd.load with InterstitialAdLoadCallback

Mobile Ads SDK Forum Advisor

unread,
May 9, 2023, 6:56:20 AM5/9/23
to zakiy...@gmail.com, google-adm...@googlegroups.com
Hello You,

Thank you for reporting this to us. 

I went ahead and tried your use case through our sample app. As per testing with Android Memory profiler, I wasn't able to reproduce the behavior on my end. Instead, the phone resources went down after loading the ad, and after showing the ad. Here's the detailed analysis for your reference.
  • CPU usage will increate up to 36% when .load method has been called
  • Once the SDK finishes loading the ad, CPU went down to 1%
  • CPU usage spike again when displaying the ad, but it will immediately go down after ad show
I also attached my screen recording for your reference. With that, could you please the following, so that we can further investigate the behavior that you're currently having?
  • AdMob App ID
  • Sample app
  • Screen recording capturing the memory leak
  • Memory profiler
Regards,
Google Logo Mobile Ads SDK Team

 

ref:_00D1U1174p._5004Q2lBjQD:ref
Screen Recording 2023-05-09 at 5_52_41 PM_mov.html

bojand...@gmail.com

unread,
Aug 21, 2023, 9:22:33 PM8/21/23
to Google Mobile Ads SDK Developers
I also have memory leaks when there are more than one activity. The GoogleAds samples only use one activity.
Is there a way to "destroy" interstitial ad.
Is there a sample code showing how to use AdMob with multi activity applications?
Thanks

Mobile Ads SDK Forum Advisor

unread,
Aug 22, 2023, 11:54:09 AM8/22/23
to bojand...@gmail.com, google-adm...@googlegroups.com
Hello,

Thank you for reaching out to us.

Currently, there is no means to "destroy" a interstitial ad. Unfortunately, we have no sample for showing how to use AdMob with multi activity applications. However, you may use our sample apps for reference: https://github.com/googleads/googleads-mobile-android-examples

For us to check the memory leak you've mentioned, kindly provide us the following information below privately:
  • Sample App
  • Steps to replicate
  • App ID
  • SDK Version
  • Complete Stack Trace Error
  • Device name and versions affected
You can provide the following details via reply privately to author option or directly provide it to the link below.

If the file(s) you are looking to share are less than 25mb in total you can attach them to this case on your next reply. If you are having trouble attaching your file to this case or if your file(s) are larger than 25mb, you can share your files with me by performing the following steps:

1. Navigate to

https://docs.google.com/forms/d/e/1FAIpQLSfkAiXMeYP-fw1W3Z-tT9uwmATEKO5X6S-th0gR2ezdKaaqfg/viewform?usp=pp_url&entry.400550049=Mobile+Ads+SDK&entry.460850823=5004Q00002lBjQDQA0&entry.80707362=00178008

2. Fill out all fields, and attach your file(s).

3. Please reply back on this thread when you have uploaded your file(s). Please do not share this link. 

This message is in relation to case "ref:_00D1U1174p._5004Q2lBjQD:ref"

Thanks,

 
Google Logo Mobile Ads SDK Team


bojand...@gmail.com

unread,
Aug 22, 2023, 12:12:12 PM8/22/23
to Google Mobile Ads SDK Developers
I already mentioned in the other thread, how i solved the interstitial and rewarded ad issue:
I was able to get rid of InterstitalAds and RewardedAds memory leaks:
1. I created objects wrappers for InterstitalAds and RewardedAds, so the object lives forever (the same as AdMob internally)
2. I used application context to load them `RewardedAd.load(context` 
3. I reset `fullScreenContentCallback null` in onDestroy
4. I pass Activity when showing interstitial or rewarded ad.

Steps 2 and 3 were not enough to get rid of memory leaks, moving the code into Objects was necessary (I guess the same would be by creating a Singleton class).

Memory leaks remain for Banner, I think they are because I use banner via xml (taken from your sample code) and it holds to the wrong context. I didn't have time to create the banner programmatically.

I must say your samples are very bad, given how many posts regarding memory leaks are out there (including stack overflow) and they are just leaking if you copy-paste the code from sample activities to your own project, if it has more than one activity and the user switches between activities.

Because I fixed it I'm not going to deliver the sample code. But I think it would be great if you do one sample code with multiple activities. 
Thank you.
Reply all
Reply to author
Forward
0 new messages