Skip to content

[firebase_messaging] Android: Memory Leak #260

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

Closed
ened opened this issue Oct 3, 2019 · 3 comments
Closed

[firebase_messaging] Android: Memory Leak #260

ened opened this issue Oct 3, 2019 · 3 comments
Labels
impact: customer A bug with low impact (e.g. affecting only a few customers or has a workaround). (P3) platform: android Issues / PRs which are specifically for Android. plugin: messaging type: bug Something isn't working

Comments

@ened
Copy link
Contributor

ened commented Oct 3, 2019

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.

@ened ened added the type: bug Something isn't working label Oct 3, 2019
@Ehesp Ehesp added platform: android Issues / PRs which are specifically for Android. plugin: messaging impact: customer A bug with low impact (e.g. affecting only a few customers or has a workaround). (P3) labels Apr 21, 2020
@ghivert
Copy link

ghivert commented Oct 30, 2020

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

@ened
Copy link
Contributor Author

ened commented Oct 30, 2020

@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
Copy link
Member

Salakar commented Nov 3, 2020

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

@Salakar Salakar closed this as completed Nov 3, 2020
@firebase firebase locked and limited conversation to collaborators Dec 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
impact: customer A bug with low impact (e.g. affecting only a few customers or has a workaround). (P3) platform: android Issues / PRs which are specifically for Android. plugin: messaging type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants