Skip to content

[firebase_messaging] Android: Memory Leak #260

Closed
@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.

Activity

added
platform: androidIssues / PRs which are specifically for Android.
impact: customerA bug with low impact (e.g. affecting only a few customers or has a workaround). (P3)
on Apr 21, 2020
ghivert

ghivert commented on Oct 30, 2020

@ghivert

I got regular memory leaks from Flutter on Android since I added Firebase Messaging. Is there any way to work around?

ened

ened commented on Oct 30, 2020

@ened
ContributorAuthor

@ghivert the plugin is currently being reworked and the memory issues will be addressed. I'm sure @Ehesp and @Salakar will come back to this issue.

Salakar

Salakar commented on Nov 3, 2020

@Salakar
Member

Hey would you be able to try out the reworked version and see if this is now sorted for you - currently a dev release (8.0.0-dev.5) - PR #4012 for reference, migration guide has also been updated: https://firebase.flutter.dev/docs/migration/

For discussion please see #4023

locked and limited conversation to collaborators on Dec 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

        Participants

        @ened@Ehesp@Salakar@ghivert

        Issue actions

          [firebase_messaging] Android: Memory Leak · Issue #260 · firebase/flutterfire