内存泄漏,直到崩溃由于HttpRequest [英] Memory leak till crash due to HttpRequest

查看:832
本文介绍了内存泄漏,直到崩溃由于HttpRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用HttpRequest,意识到内存不会在任何请求后清理。
一段时间后,Chrome中的运行标签页将崩溃。



这里是一些测试代码。将大型文件放入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 64位以及Linux 64位下试用



内存泄漏只存在于Dartium中。当我将代码编译为JS并在Firefox中运行时,内存使用量增加到3.5 GB,并保留在那里。



这真的是一个错误, ?

解决方案

有问题,但已关闭。

最近发布的更改要求以明确关闭请求,否则保持打开15秒(默认值)。



请参阅 https://code.google.com/p/dart/issues/detail?id=20833 了解详情。 p>



  import'dart:io' 

void main(List< String> args){
HttpServer.bind(InternetAddress.LOOPBACK_IP_V4,9090).then((server){
server.listen ){
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实例是正确的事情,因为它将处理共享持久连接。



< pre class =lang-dart prettyprint-override> 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 (https://www.google.com)
.then((req)=> req.close())
.then((resp)=> resp.drain())
.whenComplete(()=> request.response.close());
});
});
}


I played with HttpRequest and realized that the memory is not cleaned up after any request. After some time the running tab within Chrome will crash.

Here is some testing code. Put a large sized file into the 'web' directory and set the URL in the code accordingly.

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){
  });
}

Just rechecked, memory leak still exists:

  • Current version: 24275
  • Used duration: 30 seconds
  • Used file: chromium\chrome.dll.pdb copied into web directory of current project
  • Tried under Windows 64bit as well as Linux 64bit

The memory leak exists only in Dartium. When I compile the code to JS and run it in Firefox, the memory usage goes up to 3.5 GB and stays there.

Is this really a bug or did I something wrong?

解决方案

There is an issue but is is closed.
There was an announced change recently that requires to close the request explicitly otherwise it stays open for 15 seconds (default value).

see the discussion at https://code.google.com/p/dart/issues/detail?id=20833 for more details.

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();
          });
    });
  });
}

In code like this having a global shared HttpClient instance is the right thing to do as that will handle sharing persistent connections.

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());
    });
  });
}

这篇关于内存泄漏,直到崩溃由于HttpRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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