如何在Flutter中查找内存泄漏? [英] How to find memory leaks in Flutter?

查看:709
本文介绍了如何在Flutter中查找内存泄漏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Flutter中查找内存泄漏。
如何找到它们?以及如何为测试创建内存泄漏?

I need to find memory leaks in Flutter. How to find them? and how to create memory leaks for the test?

推荐答案

Am在android studio ide中实现了内存泄漏测试。

Am implemented Memory leack testing in android studio ide.

步骤-1:
将设备与android studio连接,然后在设备上运行应用程序。

Step - 1 : Connect your device with android studio and run your application on your device.

步骤-2 :
转到视图->工具窗口-> Flutter性能

Step - 2 : Go to View -> Tool Windows -> Flutter Performance

步骤-3:
窗口底部的打开开发工具选项将在那,点击它。它将导航到浏览器的新窗口。
有关更多详细信息,请参见下图:

Step - 3 : Bottom of the window "Open Dev Tools" option will be there, click on it. It will be navigate into new window of your browser. See below image for more details :


步骤4:
要按照屏幕快照执行以下步骤,您可以查看对象的大小和详细信息。这是造成内存泄漏的原因。
首先从可用菜单中选择内存,然后在下面的ui中看到。

Step - 4 : To follow below steps as per screen shot , you can able to see object size and details.Which are caused memory leakages. First Select "Memory" from available menus than you can able to see below ui.

 1. Click on settings icon

 2. Select "Dart" and "Flutter"  from checkbox.

 3. Click on "Apply" button.

步骤-5:
这是最后一步,现在您可以看到内存泄漏信息。

Step - 5 : This is final step, now you can able to see memory leaking info.

1. Click on "Snapshot" it will be collect and display object list in bottom of the window.
2. Click on search icon and Here you can see those classes which objects are not destroyed. Suppose am selected "ApiRepository.dart" class and instance will be available in memory ,so that details are visible in window. If multiple objects created than you can see here the total no. of instance and total size.

步骤6:
您可以使用 GC手动调用垃圾收集器。您可以随时使用重置和快照按钮重置并获取最新的快照。

Step - 6 : You can able to call Garbage Collector manually by using "GC" . You can anytime Reset and get latest snapshot using "Reset" and "Snapshot" buttons.

有关内存分配相关详细信息的更多信息,请阅读以下文章:

For more information about Memory allocation related details read below articles :

https:// medium .com / flutter / flutter-dont-fear-the-garbage-collector-d69b3ff1ca30
https://flutter.dev/docs/development/tools/devtools/memory

这篇关于如何在Flutter中查找内存泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆