flutter - 如何创建不消耗内存的轮询?
问题描述
我正在尝试创建对 API 的长时间轮询,该 API 每五秒将数据提取到应用程序的主页,该主页处于信息亭模式。因此,我添加了以下代码:
Timer.periodic(Duration(seconds: 5), (timer) async {
// code that polls for the active users from server
final response = await http.get(_url);
// rest of the code (which can be ignored)
});
这很好用,但是当我在颤振工具中跟踪配置文件模式时,我发现内存使用量及时增加。一两天后,应用程序甚至会因为内存不足异常而崩溃。如果有任何最佳实践可以在没有内存崩溃或清除的情况下执行此操作,我将不胜感激。
谢谢
解决方案
推荐阅读
- java - MySQL连接到数据库到java
- ios - 点击我的 iOS App 按钮后可以调用 Siri 吗?
- javascript - 如何对带有日期的每个页面请求的 javascript 文件进行版本控制
- ios - 如何检测 SCNNode 何时停止移动?
- python-2.7 - 如何添加缺少的 c 库以在 cygwin 中安装 lxml?
- node.js - 在 Netlify AWS lambda 函数中包含模块
- grafana - 如何在 grafana 仪表板中组合标签列表
- node.js - 如何下载使用 telegraf 模块发送到我的电报机器人的文件或照片?
- qt - 为什么 QGridLayout setRowStretch 不兑现
- r - 在ggplot中将线分配给第二个y轴