Android Admob Interstitial Memory Leak
I'm trying to show interstitials at the end of some Activities. The problem is the interstitials seem to prevent the Activities from being garbage collected causing an out-of-memor
Solution 1:
Ok i seem to have fixed it by changing
interstitial = new InterstitialAd(this);
to
interstitial = new InterstitialAd(getApplicationContext());
I don't completely understand memory management in java/android but I think whats going on is because the Activity references interstitial and interstitial has a reference to Activity so neither gets garbage-collected. Passing in the application context rather than the Activity context prevents this cycle dependency and solves the problems. Hope this helps someone :D.
Solution 2:
One thing that helped me is to invoke the interstitial.show() on the uithread (since i guess its UI-stuff u have to do it on the ui-thread)
Solution 3:
Just use application global context:
interstitial = new InterstitialAd(getApplication());
Don't use getApplicationContext()
, because returned value will be your current activity.
Post a Comment for "Android Admob Interstitial Memory Leak"