Closed
Description
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
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
ghivert commentedon 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 commentedon 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 commentedon 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