Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] fix leaking MethodChannel through anonymous class #1201

Merged
merged 1 commit into from
Oct 13, 2022

Conversation

emakar
Copy link
Contributor

@emakar emakar commented May 27, 2022

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
    ====================================

@ycv005
Copy link
Contributor

ycv005 commented Jun 23, 2022

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

@zegnus
Copy link

zegnus commented Aug 24, 2022

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

@Manuito83
Copy link
Contributor

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

This is only merged in a fork.

@pichillilorenzo pichillilorenzo merged commit f573f8a into pichillilorenzo:master Oct 13, 2022
@pichillilorenzo
Copy link
Owner

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

@allcontributors
Copy link
Contributor

@pichillilorenzo

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants