FlutterToast icon indicating copy to clipboard operation
FlutterToast copied to clipboard

MethodCallHandlerImpl.mToast leaks toast

Open pyricau opened this issue 3 years ago • 2 comments

I'm filing this issue based on a leakcanary report found on Stack Overflow: https://stackoverflow.com/questions/66911405/toast-mnextview-and-framelayout-possible-leak-how-to-trace-the-cause

The key interesting part in the leaktrace is:

├─ io.flutter.embedding.engine.dart.DartMessenger instance
│    Leaking: UNKNOWN
│    Retaining 8.0 kB in 113 objects
│    ↓ DartMessenger.messageHandlers
│                    ~~~~~~~~~~~~~~~
├─ java.util.HashMap instance
│    Leaking: UNKNOWN
│    Retaining 7.9 kB in 110 objects
│    ↓ HashMap.table
│              ~~~~~
├─ java.util.HashMap$Node[] array
│    Leaking: UNKNOWN
│    Retaining 7.8 kB in 109 objects
│    ↓ HashMap$Node[].[7]
│                     ~~~
├─ java.util.HashMap$Node instance
│    Leaking: UNKNOWN
│    Retaining 6.8 kB in 67 objects
│    ↓ HashMap$Node.next
│                   ~~~~
├─ java.util.HashMap$Node instance
│    Leaking: UNKNOWN
│    Retaining 6.8 kB in 65 objects
│    ↓ HashMap$Node.value
│                   ~~~~~
├─ io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler instance
│    Leaking: UNKNOWN
│    Retaining 6.7 kB in 62 objects
│    ↓ MethodChannel$IncomingMethodCallHandler.handler
│                                              ~~~~~~~
├─ io.github.ponnamkarthik.toast.fluttertoast.MethodCallHandlerImpl instance
│    Leaking: UNKNOWN
│    Retaining 6.7 kB in 61 objects
│    context instance of com.example.app.Application
│    ↓ MethodCallHandlerImpl.mToast
│                            ~~~~~~
├─ android.widget.Toast instance
│    Leaking: YES (This toast is done showing (Toast.mTN.mWM != null && Toast.
│    mTN.mView == null))

It shows that MethodCallHandlerImpl.mToast keeps a reference to the toast (and its view hierarchy) after it's done showing, and forever until a new toast is shown.

pyricau avatar Apr 09 '21 18:04 pyricau

+1,显示完成后toast对象没有释放

LucasDevelop avatar Apr 22 '21 10:04 LucasDevelop

+1 遇到此问题 toast对象没有释放 是否有解决的办法?

fade7 avatar Aug 27 '21 02:08 fade7