googleads / googleads-mobile-android-examples

googleads-mobile-android
Apache License 2.0
1.69k stars 1.87k forks source link

Rewarded video and Interstitial leaks activity #84

Open santimar opened 7 years ago

santimar commented 7 years ago

It seems that the interstial is holding a reference to the activity context passed on the constructor, so if you do something like

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mInterstitialAd = new InterstitialAd(this);
        ...

Your activity gets leaked

The only way i found to avoid this, is to initialize the Interstitial passing application context Same happens with Rewarded video, that you must initialize with mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(getApplicationContext()); instead of mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this);

stowy commented 7 years ago

Hi @Aiden01, thanks for the details, this seems like it is related to https://github.com/googleads/googleads-mobile-android-examples/issues/83, we are actively reviewing this issue so we'll update this when we have more info.

kmansoft commented 6 years ago

Just ran into this in our app.

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.

@stowy it's been almost a a year since the bug was filed and it's still not fixed:

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.

Please seriously consider fixing this as a priority.

stowy commented 6 years ago

thanks for the additional feedback @kmansoft, we are actively working on this and hope to have a fix in an upcoming release. Will advise when the update is scheduled.

en-archx commented 5 years ago

is this bug fixed already?

dev-vvd commented 4 years ago

@stowy Any progress on the bug? My interstitials keep leaking my activity