A memory leak occurs when an activity with AdManagerAdView is finished

367 views
Skip to first unread message

Pavel Sidyakin

unread,
Feb 27, 2023, 11:02:08 AM2/27/23
to Google Mobile Ads SDK Developers
See the sample: https://github.com/PavelSidyakin/ad_sdk_leak_demo

The app contains an activity with AdManagerAdView.

Steps:
1. Build and run the app.
2. Wait for the banner to load.
3. Tap the "Finish" button. 
4. Attach the profiler.

Expected result: no leaks.
Actual result: BannerActivity leaks. 

 Ads version: 21.5.0.

Mobile Ads SDK Forum Advisor

unread,
Feb 27, 2023, 3:34:03 PM2/27/23
to fox...@gmail.com, google-adm...@googlegroups.com

Hi Pavel,

Thank you for reaching out to Mobile Ads SDK team.

With regard to the memory leak you've encounter, as per checking the sample app from the Github project you've provided, I was able to test it in our end. However, for us to better visualize if what we seen in the profiler is what you are referring for memory leak, can you provide us screenshot and a copy of your profiler for us to better check it in our end? You can provide the following details via reply privately to author option or directly provide it to the link below.

If the file(s) you are looking to share are less than 25mb in total you can attach them to this case on your next reply. If you are having trouble attaching your file to this case or if your file(s) are larger than 25mb, you can share your files with me by performing the following steps:

1. Navigate to https://docs.google.com/forms/d/e/1FAIpQLSfkAiXMeYP-fw1W3Z-tT9uwmATEKO5X6S-th0gR2ezdKaaqfg/viewform?usp=pp_url&entry.400550049=Mobile+Ads+SDK&entry.460850823=5004Q00002jHByWQAW&entry.80707362=00168899

2. Fill out all fields, and attach your file(s).

3. Please reply back on this thread when you have uploaded your file(s). Please do not share this link.

Regards,

Google Logo Mobile Ads SDK Team


ref:_00D1U1174p._5004Q2jHByW:ref

Pavel Sidyakin

unread,
Feb 28, 2023, 4:43:25 AM2/28/23
to Google Mobile Ads SDK Developers
Hello!

The files are submitted.

You can see on the screenshots that:
1. BannerActivity is destroyed.
2. BannerActivity instance leaks.
3. AdManagerAdView holds a reference to BannerActivity.
4. Class zzea holds a reference to AdManagerAdView in property zzm (names as per version 21.5.0).

Seems like zzea is a singleton which still holds the reference to AdManagerAdView after the view is destroyed. You may want to free the reference when AdManagerAdView.destroy() is called.

However, I tied to remove the reference via reflection (by nulling zzm property). And anyway I see leaks, so probably this is not the only reason for the leak. 
I also saw a suspicious reference to the activity in a class named ap. See the screenshot. I didn't find this class in libraries. Probably it is a part of play services on the device. 

Google play services version on the device: version 23.05.14 (190400-509319212)

Note: if you remove the AdManagerAdView from the layout, the leak is not observed. 

Pavel Sidyakin

unread,
Feb 28, 2023, 10:28:28 AM2/28/23
to Google Mobile Ads SDK Developers

Hello!

I replied via a mail app to your e-mail in which you asked about screen coding. 
Have you received it? 


Mobile Ads SDK Forum Advisor

unread,
Feb 28, 2023, 4:21:49 PM2/28/23
to fox...@gmail.com, google-adm...@googlegroups.com

Hi Pavel,

We received the screen recording you've shared. I've checked it and try in our end, but still unable to replicate the memory leaks. However, let me share it to the wider team to further check. Rest assured that one of our team will reach out to you.

Regards,

Mobile Ads SDK Forum Advisor

unread,
Feb 28, 2023, 5:27:01 PM2/28/23
to fox...@gmail.com, google-adm...@googlegroups.com

Hi Pavel,

Thank you for your submission. I investigated the memory leak by modifying the sample to refresh the activity when the button was pressed. In this experiment, I would expect to see memory pressure build up as more banner ads are loaded. That said, I did not see memory build up, therefore I did not find the memory leak.

Modified sample code below with modification in bold:

package com.example.sample

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.example.sample.databinding.ActivityBannerBinding
import com.google.android.gms.ads.admanager.AdManagerAdRequest

class BannerActivity : AppCompatActivity() {
    private var _binding: ActivityBannerBinding? = null
    private val binding
        get() = _binding ?: throw IllegalStateException("Binding not initialized")

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        _binding = ActivityBannerBinding.inflate(layoutInflater)

        binding.finishButton.setOnClickListener {
            finish()
            startActivity(getIntent())
        }

        setContentView(binding.root)
        binding.adView.loadAd(AdManagerAdRequest.Builder().build())
    }

    override fun onDestroy() {
        binding.adView.destroy()
        _binding = null
        super.onDestroy()
    }
}

 

Thanks,
Nick



ref:_00D1U1174p._5004Q2jHByW:ref

Pavel Sidyakin

unread,
Mar 1, 2023, 3:52:34 AM3/1/23
to Mobile Ads SDK Forum Advisor, google-adm...@googlegroups.com
Hello!

Thank you for your reply.

I tried to reproduce the issue on an x86_64 emulator and I cannot reproduce the problem. 

However, the issue is reproducible on 3 different physical (arm64) devices. In the attachment, you can find information about the devices. 

Try to reproduce it on a physical device, please. According to the provided screenshot, you tried an emulator. 

Regards,
Pavel

devices.zip

bojand...@gmail.com

unread,
Aug 21, 2023, 9:26:47 PM8/21/23
to Google Mobile Ads SDK Developers
Any progress solving the issue? Thanks!

Mobile Ads SDK Forum Advisor

unread,
Aug 22, 2023, 1:38:26 PM8/22/23
to bojand...@gmail.com, google-adm...@googlegroups.com
Hi,

We were not able to replicate the issue on our end. If you could provide a sample with detailed steps on how to replicate this I can take another look. That said, since this is device specific it could very much be a leak with the device.
Reply all
Reply to author
Forward
0 new messages