2013-06-30 156 views
3

我使用HttpRequest進行遊戲,發現內存在任何請求後都沒有清理。 經過一段時間Chrome中的運行選項卡將崩潰。由於HttpRequest導致內存泄漏直至崩潰

以下是一些測試代碼。將大文件放入'web'目錄並相應地在代碼中設置URL。

import 'dart:async'; 
import 'dart:html'; 

void main() { 
    const PATH = "http://127.0.0.1:3030/PATH_TO_FILE"; 
    new Timer.periodic(new Duration(seconds:10), (Timer it)=>getString(PATH)); 
} 

void getString(String url){ 
    HttpRequest.getString(url).then((String data){ 
    }); 
} 

只是複查,內存泄漏仍然存在:

  • 當前版本:24275
  • 使用持續時間:30秒
  • 使用的文件:鉻\ chrome.dll.pdb複製到web目錄的當前項目
  • 在Windows 64bit以及Linux 64bit下試用

內存泄漏只存在於Dartium中。當我將代碼編譯爲JS並在Firefox中運行時,內存使用量將高達3.5 GB,並保持在那裏。

這真的是一個錯誤還是我有什麼問題?

+2

我對你的文章做了一個相當大的編輯,刪除了幾個永遠不會被調用的函數,並且使得所有的行都適合。據我所知,這抓住了你想分享的一切...... –

+0

無法用Dartium發射或JS發射(Firefox)重現。 – MarioP

+0

我重新檢查了代碼,並在我的文章中添加了一些其他信息。 –

回答

0

還有一個問題here,提示HttpRequest中有內存泄漏;但是我無法在Dart問題跟蹤器中找到任何內容。如果你認爲這可能是一個真正的內存泄漏,它可能是值得的raising a bug

0

存在問題,但已關閉。
最近有一個公佈的變化,要求明確關閉請求,否則它保持打開15秒(默認值)。

有關更多詳細信息,請參閱https://code.google.com/p/dart/issues/detail?id=20833的討論。

import 'dart:io'; 

void main(List<String> args) { 
    HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, 9090).then((server) { 
    server.listen((HttpRequest request) { 
     var client = new HttpClient(); 
     client.getUrl(Uri.parse("https://www.google.com") 
      .then((req) => req.close()) 
      .then((resp) => resp.drain()) 
      .whenComplete(() { 
      client.close(); 
      request.response.close(); 
      }); 
    }); 
    }); 
} 

在這樣的代碼有一個全局共享HttpClient的實例是來做爲將處理共享持久連接正確的事情。

import 'dart:io'; 

void main(List<String> args) { 
    HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, 9090).then((server) { 
    server.listen((HttpRequest request) { 
     var client = new HttpClient(); 
     client.getUrl(Uri.parse("https://www.google.com") 
      .then((req) => req.close()) 
      .then((resp) => resp.drain()) 
      .whenComplete(() => request.response.close()); 
    }); 
    }); 
}