Android Admob 4.3.1 still has a memory leak.

541 views
Skip to first unread message

Tim Clark

unread,
Nov 2, 2011, 1:56:02 PM11/2/11
to google-adm...@googlegroups.com
It's very easy to reproduce. Just create 2 activities with ads and switch back and forth between them... they will not get garbage collected

I posted a Stack Overflow question for 4.1.1 here: http://stackoverflow.com/questions/7695576/android-admob-4-1-1-has-a-memory-leak-see-attached-test-project-cause-fix-wor

This includes a test project for v4.1.1 but it is still relevant because the bug still exists.

WebRep
Overall rating
 

b0b

unread,
Dec 3, 2011, 8:16:31 PM12/3/11
to google-adm...@googlegroups.com
This is a real issue. I have this memory leak with orientation changes, as explained in the stackoverflow page.
Following this page workaround which is to use a static AdView seems to work, but it is still leaking the original Activity the static AdView is constructed with
(this parameter):

 mAdView = new AdView(this, AdSize.BANNER, ADMOB_PUBLISHER_ID);

Isn't there a better solution to avoid this huge memory leak ?

Changing orientation 10-20 times in my app is sufficient to trigger an OutOfMemoryException on
bitmap creation, and at this point 33Mb of native memory is used (!!!), there is none left.

Adam Zehavi

unread,
Dec 6, 2011, 3:06:52 AM12/6/11
to Google AdMob Ads Developers

b0b

unread,
Dec 6, 2011, 3:43:59 PM12/6/11
to google-adm...@googlegroups.com
You soution probably work, I will try it. It is better than to use a real Activity which may consume way more memory.

Alternatively I've discovered that destroying the WebView in onDestroy() greatly reduced the leak (but it still leaks a little):


void destroyWebView(ViewGroup viewGroup) {
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            if (viewGroup.getChildAt(i) instanceof WebView) {
                WebView view = (WebView)viewGroup.getChildAt(i);
                viewGroup.removeView(view);
                view.destroy();               
                return ;
            }
        }
    }

protected void onDestroy() {
        super.onDestroy();
        ...
       adLayout.removeAllViews();   // admobView view is a child of adLayout
       destroyWebView(admobView);
}

Reply all
Reply to author
Forward
0 new messages