Skip to content

[firebase_messaging] Android: Memory Leak #260

@ened

Description

@ened

Currently, the background handling in FlutterFirebaseMessagingService is leaking the backgroundChannel property. This get's evident by activating LeakCanary and moving the App from FG to BG:

D  ┬
D  ├─ android.net.ConnectivityThread
D  │    Leaking: NO (PathClassLoader↓ is not leaking)
D  │    Thread name: 'ConnectivityThread'
D  │    GC Root: Thread object
D  │    ↓ thread ConnectivityThread.contextClassLoader
D  ├─ dalvik.system.PathClassLoader
D  │    Leaking: NO (Object[]↓ is not leaking and A ClassLoader is never leaking)
D  │    ↓ PathClassLoader.runtimeInternalObjects
D  ├─ java.lang.Object[]
D  │    Leaking: NO (FlutterFirebaseMessagingService↓ is not leaking)
D  │    ↓ array Object[].[1679]
D  ├─ io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService
D  │    Leaking: NO (a class is never leaking)
D  │    ↓ static FlutterFirebaseMessagingService.backgroundChannel
D  │                                             ~~~~~~~~~~~~~~~~~
D  ├─ io.flutter.plugin.common.MethodChannel
D  │    Leaking: UNKNOWN
D  │    ↓ MethodChannel.messenger
D  │                    ~~~~~~~~~
D  ├─ io.flutter.view.FlutterNativeView
D  │    Leaking: UNKNOWN
D  │    ↓ FlutterNativeView.mPluginRegistry
D  │                        ~~~~~~~~~~~~~~~
D  ├─ io.flutter.app.FlutterPluginRegistry
D  │    Leaking: UNKNOWN
D  │    ↓ FlutterPluginRegistry.mActivity
D  │                            ~~~~~~~~~
D  ╰→ com.company.app.MainActivity
D  ​     Leaking: YES (Activity#mDestroyed is true and ObjectWatcher was watching this)
D  ​     key = 1fd3d04b-7f8d-4bbf-99ae-440d0fb8146c
D  ​     watchDurationMillis = 5307
D  ​     retainedDurationMillis = 306
D  , retainedHeapByteSize=160758)], libraryLeaks=[])

Expected behavior
No memory leaks.

Additional context
As @kroikie put it in the comments within service class, the isolate/instance stuff must not be static.

Metadata

Metadata

Assignees

No one assigned

    Labels

    impact: customerA bug with low impact (e.g. affecting only a few customers or has a workaround). (P3)platform: androidIssues / PRs which are specifically for Android.plugin: messagingtype: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions