-
Notifications
You must be signed in to change notification settings - Fork 340
Need a tool to detect memory leaks in a flutter app #1437
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
Comments
/cc @Aaron009 |
Fyi @terrylucas |
@jacob314 @a-siva @terrylucas I hope to have such a function. In debug mode, an object is instantiated and then marked as recyclable by code. After GC was enforced, it was found that the object could not be recycled at this time, and an error or prompt was given. |
This comment was marked as abuse.
This comment was marked as abuse.
Is something similar to https://github.com/square/leakcanary possible in Dart/Flutter? |
https://flutter.cn/community/tutorials/memory-leak-monitoring-on-flutter This is the realization idea, it is not open source, if you have any ideas, please let me know |
Once we have functionality to detect a memory leak, we should badge the memory tab with an error when a leak is detected. |
We can support this using the VM Service. Without the VM Service in the loop Dart's lack of weak reference support would get in the way. |
Duplicate of #3951 |
Here is the original text from @Aaron009 transferred from dart-lang/sdk#39645
========================================================================
I wrote a memory leak code.
import 'package:flutter/material.dart';
This is a very simple code.
Every time you click on the floatingButton, it will be continuously added to the memoryList without being removed. This is an obvious memory leak.
I once read an article about Flutter checking for memory leaks.
The principle is that the larger the memory size requested by a function, the greater the possibility of a memory leak. (I forgot where I saw it. If anyone knows, please tell me the address of this article.)
I don't like this method because the memory requested by a function is very small, but it is a memory leak and it is difficult to check.
Another way is to use weakly referenced.
The principle is this.
// According to the principle, after executing gc,
// if the memoryList key does not exist in the
//
WeakMap
,// it means that the memoryList has recovered memory normally.
This troubleshooting method is very enjoyable. When I create an object, I make a weak reference to it to store it. When I destroy and force the use of GC, we can check the memory leaked objects through WeakMap.
There are several issues:
Dart does not have a weak reference. May I ask if there is a launch plan?
Does dart have a similar method to know if the object has been properly recycled?
In addition to the above two methods, is there a better way for Flutter to check for memory leaks?
I used to develop a game in which a colleague wrote a piece of code with a memory leak and then left. It was too painful when I investigated later.
The text was updated successfully, but these errors were encountered: