Memory leaks while leaving activity

1,662 views
Skip to first unread message

kiwa...@gmail.com

unread,
Mar 31, 2021, 8:03:14 PM3/31/21
to Google Mobile Ads SDK Developers
E/WindowManager: android.view.WindowLeaked: Activity com.ihad.ptt.ArticleContentActivity has leaked window com.google.android.gms.ads.internal.webview.y{96a3b7f I.E...... ......I. 0,0-880,0} that was originally added here
        at android.view.ViewRootImpl.<init>(ViewRootImpl.java:597)
        at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:377)
        at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:95)
        at com.google.android.gms.ads.nonagon.ad.nativead.bn.b(:com.google.android.gms.policy_ads_fdr_dynamite@210402101@210402101057.356914649.356914649:12)
        at com.google.android.gms.ads.nonagon.ad.nativead.ak.n(:com.google.android.gms.policy_ads_fdr_dynamite@210402101@210402101057.356914649.356914649:3)
        at com.google.android.gms.ads.nonagon.ad.nativead.bj.onScrollChanged(:com.google.android.gms.policy_ads_fdr_dynamite@210402101@210402101057.356914649.356914649:2)
        at com.google.android.gms.ads.internal.util.weaklisteners.c.onScrollChanged(:com.google.android.gms.policy_ads_fdr_dynamite@210402101@210402101057.356914649.356914649:2)
        at android.view.ViewTreeObserver.dispatchOnScrollChanged(ViewTreeObserver.java:1164)
        at android.view.ViewRootImpl.draw(ViewRootImpl.java:3497)
        at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:3418)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2755)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1721)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7598)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:966)
        at android.view.Choreographer.doCallbacks(Choreographer.java:790)
        at android.view.Choreographer.doFrame(Choreographer.java:725)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:951)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

Frequency: Almost every time
SDK version: com.google.firebase:firebase-bom:26.8.0
Device: Android emulator
OS: Android 10

Mobile Ads SDK Forum Advisor Prod

unread,
Apr 1, 2021, 10:20:00 AM4/1/21
to kiwa...@gmail.com, google-adm...@googlegroups.com
Hi Kiwa,

Thank you for bringing this issue to our attention. I was wondering if you could share with us more information of what is happening. Steps to get the stacktrace that you are showing. As well as a simple sample app that would allow us to replicate this.

Regards,
Google Logo
William Pescherine
Mobile Ads SDK Team
 


ref:_00D1U1174p._5004Q2EoxpO:ref

Nguyen Tung

unread,
Apr 2, 2021, 1:22:56 PM4/2/21
to Google Mobile Ads SDK Developers
I 'm having the same issue. I 'm following template from https://github.com/googleads/googleads-mobile-android-examples/tree/master/kotlin/admob/NativeAdvancedExample. After ads load success and activity destroy, the logcat show this error. I tested it on my Xiao Mi A2 device, OS Android 10.
Sorry about my bad English.

Mobile Ads SDK Forum Advisor Prod

unread,
Apr 2, 2021, 4:01:05 PM4/2/21
to gre...@ridast.com, google-adm...@googlegroups.com
Hi Nguyen,

Thank you for bringing this issue to our attention. As I previously asked the other user. If youc an share with us via "Reply to author" button a link to the following information.
  • A simple sample app that reproduces the leak.
  • Any analytics or logs that show the leak with increased CPU or memory usage.
  • Any steps that you see that may cause the leak so as to make it more reproducible.

Nomad88

unread,
Apr 7, 2021, 6:04:48 AM4/7/21
to Google Mobile Ads SDK Developers
I'm also experiencing the same issue on my devices:
- Redmi 8, Android 10
- Galaxy S10e, Android 11

Reproducing steps:
1. Build and run the sample app
2. Close the activity by pressing the back button
3. You may see the log like the below one

The stacktrace:
2021-04-07 18:55:52.830 25341-25341/com.google.android.gms.example.nativeadvancedexample E/WindowManager: android.view.WindowLeaked: Activity com.google.android.gms.example.nativeadvancedexample.MainActivity has leaked window com.google.android.gms.ads.internal.webview.y{46cf476 I.E...... ......I. 0,0-640,0} that was originally added here
        at android.view.ViewRootImpl.<init>(ViewRootImpl.java:628)
        at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:377)
        at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:96)

        at com.google.android.gms.ads.nonagon.ad.nativead.bn.b(:com.google.android.gms.policy_ads_fdr_dynamite@210402101@210402101057.356914649.356914649:12)
        at com.google.android.gms.ads.nonagon.ad.nativead.ak.n(:com.google.android.gms.policy_ads_fdr_dynamite@210402101@210402101057.356914649.356914649:3)
        at com.google.android.gms.ads.nonagon.ad.nativead.bj.onGlobalLayout(:com.google.android.gms.policy_ads_fdr_dynamite@210402101@210402101057.356914649.356914649:2)
        at com.google.android.gms.ads.internal.util.weaklisteners.b.onGlobalLayout(:com.google.android.gms.policy_ads_fdr_dynamite@210402101@210402101057.356914649.356914649:2)
        at android.view.ViewTreeObserver.dispatchOnGlobalLayout(ViewTreeObserver.java:1056)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2724)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1804)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7766)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1031)
        at android.view.Choreographer.doCallbacks(Choreographer.java:854)
        at android.view.Choreographer.doFrame(Choreographer.java:789)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1016)

        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7562)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
2021년 4월 3일 토요일 오전 5시 1분 5초 UTC+9에 mobileadssdkforumadvisor님이 작성:

Mobile Ads SDK Forum Advisor Prod

unread,
Apr 7, 2021, 1:22:56 PM4/7/21
to nomad88....@gmail.com, google-adm...@googlegroups.com
Hi Nomad,

Thank you for the additional information. Allow me to bring this to my team to look at and see if there is anything that they are able to find with this. Once we get feedback we will be certain to pass it along.

Lee

unread,
Apr 11, 2021, 11:41:05 PM4/11/21
to Google Mobile Ads SDK Developers
I'm also experiencing the same problem

tom.h...@gmail.com

unread,
Apr 22, 2021, 7:02:40 AM4/22/21
to Google Mobile Ads SDK Developers
I see the same problem. I believe I destroyed native ad view correctly. Please advise

Dne pondělí 12. dubna 2021 v 5:41:05 UTC+2 uživatel Lee napsal:
Message has been deleted

Osvaldo Saez

unread,
Apr 26, 2021, 10:07:56 PM4/26/21
to Google Mobile Ads SDK Developers
I'm also experiencing this issue. It is happening when I press the back button and exit my app.

Mobile Ads SDK Forum Advisor Prod

unread,
Apr 26, 2021, 11:37:35 PM4/26/21
to oasl.ro...@gmail.com, google-adm...@googlegroups.com

Hi Osvaldo,

Thank you for reaching out to us.

Could you please provide the following details so that we can help you to your concern via Reply privately to author option or send it directly to mobileads...@gmail.com?

Regards,

Google Logo
Princess Pamela Pineda
Mobile Ads SDK Team
 


ref:_00D1U1174p._5004Q2GHnSZ:ref

Dennis Deng

unread,
May 23, 2021, 12:26:35 AM5/23/21
to Google Mobile Ads SDK Developers
It looks like the issue is caused by the new native validator, when I disable the validator in my manifest file the error goes away. Since the validator is automatically disabled for release builds, this should be okay. But one side-effect I noticed was that shared element transitions are broken with the validator on, specifically when leaving an activity that contains a native ad. I'm not sure if it's related to this leak as well, but it'd good to get it resolved as well

Komenan jean privat Kouassi

unread,
May 23, 2021, 4:44:53 PM5/23/21
to kiwa...@gmail.com, Google Mobile Ads SDK Developers
Please Can I get your number? 

--

---
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-admob-ads-sdk/8a2d0066-4505-447f-ac1e-f3506db950dcn%40googlegroups.com.

Mobile Ads SDK Forum Advisor Prod

unread,
May 24, 2021, 12:31:42 AM5/24/21
to sanpl...@gmail.com, google-adm...@googlegroups.com
Hi Dennis,

I work along with Princess. Thank you for sharing your findings.

Would you able to send a project file requested? Also, would it be possible for you to share a memory profiler capturing the behavior and as well as the case when the native validator is disabled?

Regards,
Google Logo
Teejay Wennie Pimentel
Mobile Ads SDK Team
 


ref:_00D1U1174p._5004Q2GHnSZ:ref
Message has been deleted
Message has been deleted

Mobile Ads SDK Forum Advisor Prod

unread,
May 27, 2021, 4:09:02 AM5/27/21
to sanpl...@gmail.com, google-adm...@googlegroups.com
Hi there,

Thank you for providing the requested information.

I've tested your app, and can confirm the behavior on my end. With this, let me raise this to the rest of the team for further investigation and to get their insight as well. I'll update you the soonest they provide their feedback.

As an aside, I have to mask your post as it contains sensitive information. Please refrain from posting sensitive information like project file link in the forum. Moving forward, if you want to share anything with us, you can use the "Reply Privately to Author" option to share the details privately. Below is the copy of your post scrubbed.

Here's an example project highlighting the issues. To repro the leak, just click Launch Native Ads Activity, wait for the native ad to load, then press back. There should be an error in logcat with the message: 
android.view.WindowLeaked: Activity...NativeAdActivity has leaked window

You should also be able to notice an issue with the ImageView shared element transition on exit, it basically stutters when exiting NativeAdActivity. Disabling the validator using NATIVE_AD_DEBUGGER_ENABLED in the manifest file fixes both these issue

Let me know if you have any additional questions, should be pretty straightforward to repro


Regards,
Google Logo
Teejay Wennie Pimentel
Mobile Ads SDK Team
 


ref:_00D1U1174p._5004Q2HD4Vu:ref

Dennis Deng

unread,
May 27, 2021, 7:53:08 AM5/27/21
to Google Mobile Ads SDK Developers
Noted, though the example project actually uses test ids for both app id + ad unit, so should be okay

Dennis

Anton Averin

unread,
Jan 7, 2022, 11:18:16 AM1/7/22
to Google Mobile Ads SDK Developers

Was this issue resolved?
I consistently detect leaks coming from `com.google.android.gms.ads.internal.util` still holding reference to the Activity after rotation.

Mobile Ads SDK Forum Advisor

unread,
Jan 9, 2022, 9:05:53 PM1/9/22
to anton....@axelspringer.com, google-adm...@googlegroups.com

Hello Anton,



Thank you for reaching out to us.

There seems to be no update for now; however, I allow me to make another followup for this. Rest assured that we will be updating this thread for any available information.

Regards,

Google Logo
Mark Kevin Albios
Mobile Ads SDK Team
 

 

ref:_00D1U1174p._5004Q2HD4Vu:ref

Mobile Ads SDK Forum Advisor

unread,
Apr 20, 2022, 6:47:12 PM4/20/22
to google-adm...@googlegroups.com, anton....@axelspringer.com

Hi Anton,

 

Thank you for your error report regarding the memory leak. Trying the sample application, I was unable to see any errors when I pressed the back button after viewing the advertisement. Can you please confirm the issue is persisting?

 

Thanks,

Nick



ref:_00D1U1174p._5004Q2HD4Vu:ref

Mobile Ads SDK Forum Advisor

unread,
May 16, 2022, 12:50:20 PM5/16/22
to tom.h...@gmail.com, google-adm...@googlegroups.com
Dear users,

Please let us know if the problem still persist with what devices and which SDK version.

Thanks,
Jill
Google Mobile Ads SDK Team

ref:_00D1U1174p._5004Q2EoxpO:ref

bojand...@gmail.com

unread,
Aug 21, 2023, 9:24:38 PM8/21/23
to Google Mobile Ads SDK Developers
The problem still persist. Can you create a multi-activity sample code? Your samples are only one activity, but memory leaks occur when the activity is destroyed.
com.google.android.gms:play-services-ads:20.0.0

Mobile Ads SDK Forum Advisor

unread,
Aug 22, 2023, 12:00:02 PM8/22/23
to bojand...@gmail.com, google-adm...@googlegroups.com
Hi bojandjbojan,

Technical SDK support questions specific to 20.0.0 are no longer supported on the Google Mobile Ads SDK developer forum. Please update to a supported version to receive full support, minimum v21.0.0, per our deprecation and sunset policy https://developers.google.com/admob/android/deprecation.

I would advise to update to 22.2.0 and see if the problem still persists.

Thanks,
Jill

ref:_00D1U1174p._5004Q2EoxpO:ref

bojand...@gmail.com

unread,
Aug 22, 2023, 12:10:34 PM8/22/23
to Google Mobile Ads SDK Developers
Yes it does after posting here I updated to 'com.google.android.gms:play-services-ads:22.2.0'.
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.
Reply all
Reply to author
Forward
0 new messages