PublisherAdView leaking Activity reference

1,167 views
Skip to first unread message

Thomas Renn

unread,
Apr 3, 2015, 12:31:56 PM4/3/15
to google-adm...@googlegroups.com
I feel like I must be wrong - but am seeing issues where PublisherAdView is causing memory leaks. I am seeing this across all devices, Nexus 6, Nexus 9, Moto X (2013).

Google Play Services 7.0.99 is the version on all the devices, using play services ads api 7.0.0.

I have the follow activity:

public class AdActivity extends ActionBarActivity {
PublisherAdView adView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ad_example);
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.linLayout);
adView = new PublisherAdView(this);
adView.setAdSizes(AdSize.SMART_BANNER);
adView.setAdUnitId("/6499/example/banner");
        adView.loadAd(new PublisherAdRequest.Builder().build());
linearLayout.addView(adView);
}

@Override
protected void onResume() {
adView.resume();
super.onResume();
}

@Override
protected void onPause() {
adView.pause();
super.onPause();
}

@Override
protected void onStop() {
adView.destroy();
super.onStop();
}
}



After rotating the device multiple times, or entering and exiting the activity (from another activity), I manually cause GC to make sure the references should be cleared. When I open up a heap dump, I see multiple AdActivity objects.


If I do not actually load an ad, adView.loadAd(...), I don't see any leaks. Am I missing something?

Thomas Renn

unread,
Apr 3, 2015, 12:52:06 PM4/3/15
to google-adm...@googlegroups.com
additional info

Nexus 9, OS 5.0.1, play services (1809214-446)

Nexus 6, OS 5.1, play services (1809214-430)

Ram Parameswaran (Mobile SDK Team)

unread,
Apr 6, 2015, 5:48:46 PM4/6/15
to google-adm...@googlegroups.com
I have filed a bug report on this issue and will follow up once I receive more information.

- Ram

Thomas Renn

unread,
Apr 10, 2015, 10:05:40 AM4/10/15
to google-adm...@googlegroups.com
Thanks for the response Ram! Has there been any more information on confirmation or when it may be resolved? 

Ram Parameswaran (Mobile SDK Team)

unread,
Apr 10, 2015, 12:45:05 PM4/10/15
to google-adm...@googlegroups.com
At this time I have no new information on this issue but it is currently being looked into.

- Ram

Ram Parameswaran (Mobile SDK Team)

unread,
Apr 16, 2015, 5:26:25 PM4/16/15
to google-adm...@googlegroups.com
I just received confirmation that a two part fix for this issue should be pushed out in an upcoming Google Play Services and WebView update.

- Ram

Andy Fisher

unread,
May 9, 2015, 1:35:18 AM5/9/15
to google-adm...@googlegroups.com
Was this fixed in 7.3.0 as I'm still seeing the issue?

Chris

unread,
May 9, 2015, 3:03:41 AM5/9/15
to google-adm...@googlegroups.com
You have adView.destroy in onStop.
When the activity is started again and then resumed the adView was destroyed but never created again
 

On Friday, April 3, 2015 at 12:31:56 PM UTC-4, Thomas Renn wrote:

Ram Parameswaran (Mobile SDK Team)

unread,
May 11, 2015, 6:51:37 PM5/11/15
to google-adm...@googlegroups.com, antonvo...@gmail.com
The fix for this issue was included in the 7.3.0 release and and an update to WebView. It is no longer reproducible on my end. Do you have any allocation logs indicating a memory leak?

- Ram
Message has been deleted

Sebastian Engel

unread,
Aug 11, 2015, 11:44:10 AM8/11/15
to Google Mobile Ads SDK Developers
I still have this issue on Play Services 7.8.99.
I could fix it by using the application context instead of the activity instance as context for the PublisherAdView: new PublisherAdView(context.getApplicationContext());

Andre Classen

unread,
Feb 22, 2016, 6:45:12 AM2/22/16
to Google Mobile Ads SDK Developers
I'm using Play Service Version 8.4 and the ad is still leaking the context.
Of course i'm calling all lifecycle methods and i can only avoid it using the application context.
Can anyone confirm this ?


Ram Parameswaran (Mobile SDK Team)

unread,
Feb 22, 2016, 5:18:47 PM2/22/16
to Google Mobile Ads SDK Developers
On a Nexus 6 with Google Play Services 8.4 I am having trouble reproducing this leak. Are you able to reproduce this issue in our sample application?

- Ram

Andre Classen

unread,
Feb 29, 2016, 12:29:55 PM2/29/16
to google-adm...@googlegroups.com
I'm using the PublisherAdView and the leak also appears in the provided sample app:
https://github.com/googleads/googleads-mobile-android-examples/tree/master/advanced/APIDemo/app/src/main

--

---
You received this message because you are subscribed to a topic in the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-admob-ads-sdk/DnICRC67ASI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-admob-ads...@googlegroups.com.
To post to this group, send email to google-adm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andre Classen

unread,
Feb 29, 2016, 12:31:59 PM2/29/16
to Google Mobile Ads SDK Developers
I'm using the PublisherAdView and the leak also appears in the provided sample app (using emulator or nexus 5 device):

https://github.com/googleads/googleads-mobile-android-examples/tree/master/advanced/APIDemo/app/src/main

Chantell Osejo

unread,
Oct 17, 2016, 3:31:58 PM10/17/16
to Google Mobile Ads SDK Developers
I'm seeing this as well.

On my screens without ad requests, my memory allocation (without interacting with the screen) stays static and flat. On screens that have the PublisherAdView, I can watch the memory monitor increase ~0.5MB every single time I make a request.

I've tried nullifying the PublisherAdView to force the resources to be released on GC, but that doesn't resolve anything (I even tried manually forcing a GC with System.gc() in desperation). I tried the workaround suggested and used application context instead of activity context; that didn't resolve it either.

This bug is killing my app's performance. It's especially bad when the user spends a long period of time in an Activity. My app has a screen that users can easily spend 30 minutes or more on. It freezes well before it ever hits that point and I get an ANR...all because of this bug.

Would appreciate an update or to have someone take a look at this.

Vu Chau (Mobile Ads SDK Team)

unread,
Oct 17, 2016, 5:25:39 PM10/17/16
to Google Mobile Ads SDK Developers
Hi Chantell,

Which version of the Mobile Ads SDK is your app currently compiled against?

Vu Chau
Mobile Ads SDK Team

attila....@gmail.com

unread,
Feb 12, 2017, 5:39:18 PM2/12/17
to Google Mobile Ads SDK Developers
Any news on this problem? I'm still seeing this.

We're using this version:

com.google.android.gms:play-services-ads:10.0.1


Chris Feldman (Mobile Ads SDK Team)

unread,
Feb 13, 2017, 2:58:05 PM2/13/17
to Google Mobile Ads SDK Developers
Hi,

We are looking into the issue and will follow-up with you if any updates or changes are made. Thank you for brining this to our attention.

Regards,
Chris Feldman
Mobile Ads SDK Team

Andrew Kean Guan

unread,
May 17, 2017, 8:01:10 AM5/17/17
to Google Mobile Ads SDK Developers
Hi Chris,
any updates on your investigation?

Thanks

Chris Feldman (Mobile Ads SDK Team)

unread,
May 17, 2017, 3:15:26 PM5/17/17
to Google Mobile Ads SDK Developers
Hi Andrew,

Nothing to report yet. Thank you for following up. We will let you know as soon as we have any new information.

Regards,
Chris Feldman
Mobile Ads SDK Team

Chad Owens

unread,
Jun 27, 2017, 10:27:05 PM6/27/17
to Google Mobile Ads SDK Developers
Is this never going to get addressed? This is causing huge issues with other libraries that rely on WeakReferences or an activity having a single instance.
Message has been deleted

Chris Feldman (Mobile Ads SDK Team)

unread,
Jun 28, 2017, 2:46:48 PM6/28/17
to Google Mobile Ads SDK Developers
Hi Chad,

This is still being looked at by our team. We've isolated multiple memory leaks. At this time, one is fixed and we are continuing work on the others. I will let you know as soon as I have another update.

Regards,
Chris Feldman
Mobile Ads SDK Team

Parker K

unread,
Jul 24, 2017, 2:05:11 PM7/24/17
to Google Mobile Ads SDK Developers
While the issues are being dealt with, I found I was able to solve the issue by passing the applicationContext to the AdView, instead of the activity/fragment context.


On Friday, April 3, 2015 at 12:31:56 PM UTC-4, Thomas Renn wrote:

Chris Feldman (Mobile Ads SDK Team)

unread,
Aug 17, 2017, 2:38:14 PM8/17/17
to Google Mobile Ads SDK Developers
Hi All,

As of the latest SDK release, you should no longer be seeing these memory leaks. Please let me know if you continue to have issues.

Regards,
Chris Feldman
Mobile Ads SDK Team

Reply all
Reply to author
Forward
Message has been deleted
0 new messages