Our app is getting hit pretty hard by a memory leak. I\'ve found that the root cause is the AdMob AdView keeping references to old activities. The problem is pretty well d
I was seeing this same leak with the 6.1.0 SDK, but was able to resolve it by calling destroy() on the AdView in question in my Activity's onDestroy. I think they have fixed it. The destroy() seems to get rid of the PhantomReferences that the AdView's WebView had to my Activity that was keeping the Activity from being GC.
Ravishi,
Your question is to the point, and I have failed to address it in my solution. As far as I can tell the solution I've found works only dynamically, where you can choose your activity while calling the sdk...
The reason my code does not have a use example, is because my solution is a bit more complicated then the one I presented, involving an entire wrapping framework I've build around the Android framework, where the AdMob relation to the application is via an intermediate module, which puts the ad dynamically using the single activity instance.
I really doubt you can avoid the memory leak simply using the Android XML.
In any case, if you are into the memory leak business, you might as well check out your AsyncTask usage... it also has its own memory leak behavior... so here is my solution
best of luck...
-- UPDATE -- 07/10/14
Someone just upvoted my answer, its preposterous that this issue still exists, it has been almost three years since my original answer, and people still have memory leaks in their apps because of AdMob... from Google... that made Android....
Anyway, I just wanted to add that you should probably set the theme of the AdMobActivity to transparent, it would prevent the flickering.
-- UPDATE -- 28/02/16
Four years...
-- UPDATE -- 09/03/17
Five years... Someone at Google please wake up, and hire real monkey to do the job :)
Adam.
I am using "play-services-ads:7.5.0" and it was not necesary to create de AdMobActivity. It worked by:
Creating adView dinamically
mAdView = new AdView(getApplicationContext(), AdSize.BANNER, banner_ad_unit_id); mAdsContainer.addView(mAdView);
Removing all views from linearLayout on destroy and destroying adView
mAdView.setAdListener(null);
mAdsContainer.removeAllViews();
mAdView.destroy();
Unfortunatelly Interstitial still leaks