flutter_inappwebview icon indicating copy to clipboard operation
flutter_inappwebview copied to clipboard

[Android] fix leaking `MethodChannel` through anonymous class

Open emakar opened this issue 2 years ago • 3 comments

anonymous class leaked ServiceWorkerManager -> MethodChannel which in turn leaks FlutterJNI

    ====================================
    HEAP ANALYSIS RESULT
    ====================================
    1 APPLICATION LEAKS
    
    References underlined with "~~~" are likely causes.
    Learn more at https://squ.re/leaks.
    
    10148702 bytes retained by leaking objects
    Signature: 3d5c9137904a59005331101308120bc8520c4bcd
    ┬───
    │ GC Root: Global variable in native code
    │
    ├─ org.chromium.android_webview.AwBrowserContext instance
    │    Leaking: UNKNOWN
    │    Retaining 33 B in 1 objects
    │    ↓ AwBrowserContext.c
    │                       ~
    ├─ pa instance
    │    Leaking: UNKNOWN
    │    Retaining 10.2 MB in 2051 objects
    │    ↓ pa.a
    │         ~
    ├─ ed0 instance
    │    Leaking: UNKNOWN
    │    Retaining 10.2 MB in 2048 objects
    │    ↓ ed0.a
    │          ~
    ├─ androidx.webkit.internal.FrameworkServiceWorkerClient instance
    │    Leaking: UNKNOWN
    │    Retaining 10.2 MB in 2047 objects
    │    ↓ FrameworkServiceWorkerClient.mImpl
    │                                   ~~~~~
    ├─ com.pichillilorenzo.flutter_inappwebview.ServiceWorkerManager$2 instance
    │    Leaking: UNKNOWN
    │    Retaining 10.2 MB in 2046 objects
    │    Anonymous subclass of androidx.webkit.ServiceWorkerClientCompat
    │    ↓ ServiceWorkerManager$2.this$0
    │                             ~~~~~~
    ├─ com.pichillilorenzo.flutter_inappwebview.ServiceWorkerManager instance
    │    Leaking: UNKNOWN
    │    Retaining 10.2 MB in 2045 objects
    │    ↓ ServiceWorkerManager.channel
    │                           ~~~~~~~
    ├─ io.flutter.plugin.common.MethodChannel instance
    │    Leaking: UNKNOWN
    │    Retaining 10.2 MB in 2044 objects
    │    ↓ MethodChannel.messenger
    │                    ~~~~~~~~~
    ├─ io.flutter.embedding.engine.dart.DartExecutor instance
    │    Leaking: UNKNOWN
    │    Retaining 10.2 MB in 2043 objects
    │    ↓ DartExecutor.flutterJNI
    │                   ~~~~~~~~~~
    ├─ io.flutter.embedding.engine.FlutterJNI instance
    │    Leaking: UNKNOWN
    │    Retaining 10.2 MB in 1649 objects
    │    ↓ FlutterJNI.localizationPlugin
    │                 ~~~~~~~~~~~~~~~~~~
    ├─ io.flutter.plugin.localization.LocalizationPlugin instance
    │    Leaking: UNKNOWN
    │    Retaining 10.1 MB in 1600 objects
    │    context instance of com.example.TestActivity with mDestroyed = true
    │    ↓ LocalizationPlugin.context
    │                         ~~~~~~~
    ╰→ com.example.TestActivity instance
    ​     Leaking: YES (ObjectWatcher was watching this because com.example.TestActivity received
    ​     Activity#onDestroy() callback and Activity#mDestroyed is true)
    ​     Retaining 10.1 MB in 1598 objects
    ​     key = 7b90c6de-3ca0-4deb-9772-2919d7815fa8
    ​     watchDurationMillis = 6891
    ​     retainedDurationMillis = 1847
    ​     mApplication instance of com.example.App
    ​     mBase instance of android.app.ContextImpl
    ====================================

emakar avatar May 27 '22 06:05 emakar

@pichillilorenzo any update on this PR ? It looks important.

ycv005 avatar Jun 23 '22 17:06 ycv005

@ycv005 this looks merged, can we close this pull request?

zegnus avatar Aug 24 '22 10:08 zegnus

@ycv005 this looks merged, can we close this pull request?

This is only merged in a fork.

Manuito83 avatar Aug 24 '22 10:08 Manuito83

Thanks! @all-contributors please add @emakar for code

pichillilorenzo avatar Oct 13 '22 13:10 pichillilorenzo

@pichillilorenzo

I've put up a pull request to add @emakar! :tada:

allcontributors[bot] avatar Oct 13 '22 13:10 allcontributors[bot]