yandexmobile / yandex-ads-sdk-android

Other
80 stars 22 forks source link

Утечка памяти #124

Closed alexmedv closed 2 years ago

alexmedv commented 2 years ago

Использую версию 5.0.0 и вижу утечку памяти. Где-то внутри SDK остается ссылка на мою активити из которой я показываю InterstitialAd. Проблема наблюдается при использовании медиации AdMob. (с рекламой от яндекса нет проблем таких)

В демонстрационном примере проблема тоже воспроизводится (нужно открыть InterstitialMobileMediationActivity , выбрать в списке AdMob, загрузить рекламу и сменить ориентацию экрана чтоб активити пересоздалась).

LeakCanary выдает такой отчет:


    ====================================
    HEAP ANALYSIS RESULT
    ====================================
    1 APPLICATION LEAKS

    References underlined with "~~~" are likely causes.
    Learn more at https://squ.re/leaks.

    419312 bytes retained by leaking objects
    Displaying only 1 leak trace out of 2 with the same signature
    Signature: 6e658434069e5d4147ab6eca3647b1bd5587b
    ┬───
    │ GC Root: Global variable in native code
    │
    ├─ com.google.android.gms.dynamic.ObjectWrapper instance
    │    Leaking: UNKNOWN
    │    Retaining 528 bytes in 1 objects
    │    ↓ ObjectWrapper.a
    │                    ~
    ├─ com.google.android.gms.ads.internal.webview.y instance
    │    Leaking: UNKNOWN
    │    Retaining 108011 bytes in 1356 objects
    │    View not part of a window view hierarchy
    │    View.mAttachInfo is null (view detached)
    │    View.mWindowAttachCount = 1
    │    mContext instance of com.google.android.gms.ads.internal.webview.aw, wrapping com.yandex.ads.sample.Application
    │    ↓ y.a
    │        ~
    ├─ com.google.android.gms.ads.internal.webview.ac instance
    │    Leaking: UNKNOWN
    │    Retaining 10716 bytes in 249 objects
    │    View not part of a window view hierarchy
    │    View.mAttachInfo is null (view detached)
    │    View.mWindowAttachCount = 1
    │    p instance of com.google.android.gms.ads.internal.webview.aw, wrapping com.yandex.ads.sample.Application
    │    mContext instance of com.google.android.gms.ads.internal.webview.aw, wrapping com.yandex.ads.sample.Application
    │    ↓ ac.aa
    │         ~~
    ├─ android.view.WindowManagerImpl instance
    │    Leaking: UNKNOWN
    │    Retaining 30238 bytes in 525 objects
    │    mContext instance of android.app.ContextImpl, not wrapping known Android context
    │    ↓ WindowManagerImpl.mContext
    │                        ~~~~~~~~
    ├─ android.app.ContextImpl instance
    │    Leaking: YES (ContextImpl.mOuterContext is an instance of com.yandex.ads.sample.mediation.mobile.interstitial.
    │    InterstitialMobileMediationActivity with Activity.mDestroyed true)
    │    Retaining 4479 bytes in 45 objects
    │    mAutofillClient instance of com.yandex.ads.sample.mediation.mobile.interstitial.
    │    InterstitialMobileMediationActivity with mDestroyed = true
    │    mOuterContext instance of com.yandex.ads.sample.mediation.mobile.interstitial.InterstitialMobileMediationActivity
    │    with mDestroyed = true
    │    ↓ ContextImpl.mAutofillClient
    ╰→ com.yandex.ads.sample.mediation.mobile.interstitial.InterstitialMobileMediationActivity instance
    ​     Leaking: YES (ObjectWatcher was watching this because com.yandex.ads.sample.mediation.mobile.interstitial.
    ​     InterstitialMobileMediationActivity received Activity#onDestroy() callback and Activity#mDestroyed is true)
    ​     Retaining 209742 bytes in 2006 objects
    ​     key = 72020aa5-eb5c-4bc4-9e55-7ab5355d8373
    ​     watchDurationMillis = 5595
    ​     retainedDurationMillis = 595
    ​     mApplication instance of com.yandex.ads.sample.Application
    ​     mBase instance of androidx.appcompat.view.ContextThemeWrapper, not wrapping known Android context
    ====================================
    0 LIBRARY LEAKS

    A Library Leak is a leak caused by a known bug in 3rd party code that you do not have control over.
    See https://square.github.io/leakcanary/fundamentals-how-leakcanary-works/#4-categorizing-leaks
    ====================================
    METADATA

    Please include this in bug reports and Stack Overflow questions.

    Build.VERSION.SDK_INT: 29
    Build.MANUFACTURER: HUAWEI
    LeakCanary version: 2.5
    App process name: com.yandex.ads.mobile
    Stats: LruCache[maxSize=3000,hits=5801,misses=92014,hitRate=5%]
    RandomAccess[bytes=4555454,reads=92014,travel=46343125844,range=26300246,size=32038734]
    Analysis duration: 7957 ms
    Heap dump file path: /data/user/0/com.yandex.ads.mobile/files/leakcanary/2022-04-03_20-54-47_341.hprof
    Heap dump timestamp: 1649008499745
    Heap dump duration: 4047 ms
    ====================================```
mobile-ads-github commented 2 years ago

Добрый день! Спасибо за информацию о проблеме, возьмем ее в работу.

mobile-ads-github commented 2 years ago

Добрый день! Мы исследовали утечку и пришли к выводу, что она находиться в AdMob SDK. Мы создали issue в их репозитории https://github.com/googleads/googleads-mobile-android-examples/issues/441