Activity Memory Leak

290 views
Skip to first unread message

Dan Klemme

unread,
Oct 7, 2017, 1:11:04 AM10/7/17
to Google Mobile Ads SDK Developers
Hello, I was following this guide for implementing rewarded videos in AdMob on Android, and doing so caused my app to have a memory leak. I only added the simple code exactly as it is in the guide, and when I remove that code, there is no memory leak. Since it's a full Activity that is getting leaked, I worry that it will be far too much for my app. Is there some better way to implement AdMob ads that doesn't cause a memory leak? After reading the first answer of this StackOverflow post, it seems the issue has been present for five years or more, which seems way too long to me. Do I really need to make a "dummy" activity to limit the damage that the memory leak causes? I ran into other issues when I tried doing that, so if that is the case I will probably need to try to find another ad network. Thanks in advance for any help you're able to give me.

Ivan Bautista (Mobile Ads SDK Team)

unread,
Oct 9, 2017, 3:22:33 AM10/9/17
to Google Mobile Ads SDK Developers
Hi Dan,

There's a known issue that might be related to this that is actively being worked on by the team. For us to confirm if this is related or if we need to raise a new issue, could you provide to us the stack trace that shows the leak as well as the replication steps you did on your end using the code sample?

Regards,
Ivan Bautista
Mobile Ads SDK Team

Ivan Bautista (Mobile Ads SDK Team)

unread,
Oct 19, 2017, 3:54:59 AM10/19/17
to google-adm...@googlegroups.com
Hi Dan,

I just want to check with you on this issue. For us to investigate further on the issue you encountered on your end, would you be able to provide to us the stack trace that shows the leak on your end using the code sample?

Dan Klemme

unread,
Oct 19, 2017, 3:07:27 PM10/19/17
to Google Mobile Ads SDK Developers
Hi Ivan,

My apologies, I somehow managed to completely miss your previous reply a couple weeks back. Anyway, when you say Stack Trace, where in the code do you want that from? I haven't had it actually throw an error at me yet, but when looking at the Heap, even after garbage collection there are always several "MainActivity" instances floating around when the AdMob ad object is instantiated. I made a gist file here for that heap if you are able to look at that. Otherwise, I made a "minimum build" version of the app with basically just Admob stuff to recreate the issue. If I do something that causes onDestroy to be called, like rotate the phone for example, the old instances of MainActivity are kept in memory. It's fairly easy to see what's going on from this hopefully.

Here's a dropbox link to a ZIP file of the full project:


Please let me know if this is enough for you to confirm the issue, or if I am misunderstanding what you are wanting specifically in a Stack Trace.

Best,
Dan

Ivan Bautista (Mobile Ads SDK Team)

unread,
Oct 20, 2017, 3:48:16 AM10/20/17
to Google Mobile Ads SDK Developers
Hi Dan,

Thank you for making extra effort to provide to us a sample app for us to investigate on. 

I ran your sample app on my end and captured a snapshot of the Java heap when onDestroy was called. I will relay this information to the rest of the team and get back to you for any official feedback.

cuestion...@gmail.com

unread,
Jan 28, 2018, 6:31:46 PM1/28/18
to Google Mobile Ads SDK Developers
Hi Ivan,

The problem still persists... any ETA update on fix?

Ivan Bautista (Mobile Ads SDK Team)

unread,
Jan 28, 2018, 10:48:22 PM1/28/18
to Google Mobile Ads SDK Developers
Hi,

Thank you for your patience and for checking in. 

The team is still actively working on this. We will provide updates in this thread once we get an official feedback from the team.

Kostya Vasilyev

unread,
Jul 9, 2018, 6:08:24 AM7/9/18
to Google Mobile Ads SDK Developers
Hello,

The bug is still present in SDK 12.0.1

Ivan - can you guys please make fixing this bug a priority?

We use just "basic" Interstitial ads - not "rewarded videos" - directly from Java.


And yes "new InterstitialAd(activity)" does leak the activity instance every time.


The leak is not the callback (and so setting it to null does not help), it's a instance of "bx" (obfuscated name) which in turn holds a "hard" reference to the context.


It seems there are several of these "bx" objects per each InterstitialAd.


I tested with ads-lite 12.0.1 using Android Studio memory analyzer.


Leaking Activity objects is bad. They're typically fairly large with a large memory tree - fragments, views, data model, etc. and so this leak can easily cause crashes.


And crashes are bad for users, and also bad for developers because of Android Vitals.


-- K

mobileadssdk-a...@google.com

unread,
Jul 10, 2018, 2:37:22 PM7/10/18
to Kostya Vasilyev, Google Mobile Ads SDK Developers
Hi, 

Our engineers are actively working on this as a priority, we realize it's been open some time. There are actually a few ongoing initiatives because there are a few underlying issues.

I will update with an expected release date as soon as possible.

Regards

Sam


=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+ page:
    http://googleadsdeveloper.blogspot.com
    https://plus.google.com/115658573333388777174/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

--

---
You received this message because you are subscribed to the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this group and stop receiving emails from it, 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.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-admob-ads-sdk/3eaa43bb-95da-40bf-85cd-a876cdbaa7e1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Lucas

unread,
Oct 14, 2018, 12:45:44 PM10/14/18
to Google Mobile Ads SDK Developers
Hi Mobile Ads SDK team,

Are there any more updates on when a fix will be available for this please? LeakCanary is still reporting leaks of activities when I display banner ads using the latest SDK, com.google.android.gms:play-services-ads:17.0.0.

Can you advise what workaround to use until a fix is available? I'm contemplating removing ads altogether from my app at this rate, which seems pretty drastic:(.
Thanks, Lucas.

mobileadssdk-a...@google.com

unread,
Oct 29, 2018, 4:57:55 PM10/29/18
to Lucas, Google Mobile Ads SDK Developers

Hi Lucas, 

Sorry for the delayed reply, for some reason this got stuck in my inbox while I was OOO.

This is tracking leaks with rewarded and interstitial ads, we are not aware of leaks being created due to banner ads, are you certain that this is caused by the SDK?

Can you file a separate thread and include details on your implementation and perhaps a reproducing sample?

Regards

Sam

=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+ page:
    http://googleadsdeveloper.blogspot.com
    https://plus.google.com/115658573333388777174/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

--

---
You received this message because you are subscribed to the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this group and stop receiving emails from it, 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.

Lucas

unread,
Nov 2, 2018, 1:34:40 PM11/2/18
to Google Mobile Ads SDK Developers
Hi Sam,

Not sure you got my previous reply.  Many thanks for getting back to me. I've posted a new thread regarding the banner ads at https://groups.google.com/d/topic/google-admob-ads-sdk/rxho6omy058/discussion . Having trouble attaching the sample to it though...
Lucas.

mobileadssdk-a...@google.com

unread,
Nov 2, 2018, 5:27:28 PM11/2/18
to Lucas, Google Mobile Ads SDK Developers
Hi Lucas,

Thanks yes it appears you were able to send the sample over and the support team is also reviewing it.

I will take a look alongside the interstitial case we are currently reviewing.

Cheers

Sam


=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+ page:
    http://googleadsdeveloper.blogspot.com
    https://plus.google.com/115658573333388777174/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

On 11/02/18 10:34:40 oak...@gmail.com wrote:
Hi Sam,

Not sure you got my previous reply.  Many thanks for getting back to me. I've posted a new thread regarding the banner ads at https://groups.google.com/d/topic/google-admob-ads-sdk/rxho6omy058/discussion . Having trouble attaching the sample to it though...
Lucas.

On Monday, 29 October 2018 20:57:55 UTC, mobileadssdk-a...@google.com wrote:

Hi Lucas, 

Sorry for the delayed reply, for some reason this got stuck in my inbox while I was OOO.

This is tracking leaks with rewarded and interstitial ads, we are not aware of leaks being created due to banner ads, are you certain that this is caused by the SDK?

Can you file a separate thread and include details on your implementation and perhaps a reproducing sample?

Regards

Sam

=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+ page:
    http://googleadsdeveloper.blogspot.com
    https://plus.google.com/115658573333388777174/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

On 10/14/18 09:45:44 oak...@gmail.com wrote:
Hi Mobile Ads SDK team,

Are there any more updates on when a fix will be available for this please? LeakCanary is still reporting leaks of activities when I display banner ads using the latest SDK, com.google.android.gms:play-services-ads:17.0.0.

Can you advise what workaround to use until a fix is available? I'm contemplating removing ads altogether from my app at this rate, which seems pretty drastic:(.
Thanks, Lucas.

--

---
You received this message because you are subscribed to the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads-sdk+unsubscrib...@googlegroups.com.

--

---
You received this message because you are subscribed to the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this group and stop receiving emails from it, 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.

Lucas

unread,
Nov 3, 2018, 5:45:01 AM11/3/18
to Google Mobile Ads SDK Developers
Ok, that's good news - thanks Sam!
Reply all
Reply to author
Forward
0 new messages