Dart HttpRequest轮询 [英] Dart HttpRequest polling

查看:533
本文介绍了Dart HttpRequest轮询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网络应用程序,它有一个定时器,触发轮询,每3秒获取数据。



我的请求Dart看起来像这样






.catchError((e)=> _recentHistoryError(e));

你能想到为什么会发生这种情况的任何原因吗?我认为这是一个内存泄漏...



编辑
这是我的 _recentHistoryResponse / code>

  void _recentHistoryResponse(String data)
{
Map obj = JSON.decode(data);
if(obj ['status'] =='success')
{
list processes = obj ['data'] ['processes'];
List newItems = new List();

列表oldIdsArray = new List();

int length = appDataDic.load_history_list.length;
for(HistoryDataVO oldVO in appDataDic.load_history_list)
{
oldIdsArray.add(oldVO.loadID);
}

for(进程中的映射进程)
{
HistoryDataVO dataVO = new HistoryDataVO();
dataVO.loadID = process ['loadID'];
dataVO.time = process ['time'];
dataVO.loadType = process ['loadType'];
dataVO.fileName = process ['fileName'];
dataVO.label = process ['label'];
dataVO.description = process ['description'];
dataVO.count = process ['count'];
dataVO.progress = process ['progress'];
dataVO.loadTask = process ['loadTask'];

//检查项目当前是否在列表中
if(length> = 1)
{
if(!LoadHistoryHelper.exists(oldIdsArray,dataVO .loadID))
{
dataVO.isNew = true;
}
}

newItems.add(dataVO);
}

appDataDic.load_history_list.clear();
appDataDic.load_history_list.addAll(newItems);

}
}

我已注释掉exists检查!LoadHistoryHelper.exists(oldIdsArray,dataVO.loadID))(因为这似乎是显而易见的地方),但它的VM仍然崩溃。



此外,我已经采取了相同的代码,并把它放入一个孤立的应用程序,唯一的真正的区别是轮询检查是 appDataDic.load_history_list 只是一个 @observable列表,而不是 ObservableList



编辑2:
好​​吧,我发现 Map obj = JSON.decode(data); 导致崩溃。我在一个Javascript论坛读取超时导致内存不被释放(我从来没有想过这个,但它是有道理的),这是真的吗?任何人都能想出一个更好的方法来做到这一点?我可以直接调用垃圾回收吗?

解决方案

还有另一个问题在这里,建议在HttpRequest中的内存泄漏;但我无法在Dart问题跟踪器中找到任何东西。如果您认为这可能是真正的内存泄漏,可能值得提出错误


I have a web app that have a Timer that fires a poll to get data every 3 seconds. It works fine for about 2.5 minutes then Chromium crashes.

My request Dart looks like this

HttpRequest.getString('data/get_load_history_recent.json')
  .then((e) => _recentHistoryResponse(e))
  .catchError((e) => _recentHistoryError(e));

Can you think of any reasons why this would happen? I assume it's a memory leak...

Edit: Here is my _recentHistoryResponse()

void _recentHistoryResponse(String data)
{
  Map obj = JSON.decode(data);
  if(obj['status'] == 'success')
  {
    List processes = obj['data']['processes'];
    List newItems = new List();

    List oldIdsArray = new List();

    int length = appDataDic.load_history_list.length;
    for(HistoryDataVO oldVO in appDataDic.load_history_list)
    {
      oldIdsArray.add(oldVO.loadID);
    }

    for(Map process in processes)
    {
      HistoryDataVO dataVO = new HistoryDataVO(); 
      dataVO.loadID = process['loadID'];
      dataVO.time = process['time'];
      dataVO.loadType = process['loadType'];
      dataVO.fileName = process['fileName'];
      dataVO.label = process['label'];
      dataVO.description = process['description'];
      dataVO.count = process['count'];
      dataVO.progress = process['progress'];
      dataVO.loadTask = process['loadTask'];

      // Check if the item is currently in the list
      if(length >= 1)
      {
        if(!LoadHistoryHelper.exists(oldIdsArray, dataVO.loadID))
        {
          dataVO.isNew = true;
        }
      }

      newItems.add(dataVO);
    }

    appDataDic.load_history_list.clear();
    appDataDic.load_history_list.addAll(newItems);

  }
}

I have commented out the exists check !LoadHistoryHelper.exists(oldIdsArray, dataVO.loadID)) (because this seemed like the obvious place) but it the VM still crashes.

Also, I have taken this same code and put it into an isolated app with the only real difference in the poll check is appDataDic.load_history_list is just an @observable List, not an ObservableList.

Edit 2 : Ok, so I have discovered that Map obj = JSON.decode(data); causes the crash. I was reading in a Javascript forum that timeouts cause the memory to not be released (I had never thought of this but it makes sense), is this true? Can any one think of a better way to do this? Can I directly call the garbage collection? I'm running out of ideas.

解决方案

There's another question here, suggesting a memory leak in HttpRequest; however I'm not able to find anything in the Dart issue tracker. If you think this might be a real memory leak, it might be worth raising a bug.

这篇关于Dart HttpRequest轮询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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