@DannyTuppeny의 문제가 해결되지 않으면 당신이 할 수있는 힙 크기를 늘리십시오. 나는 이것이이
old_gen_heap_size: 1024 (Max size of old gen heap size in MB,e.g: --old_gen_heap_size=1024 allows up to 1024MB old gen heap)
dart --old_gen_heap_size=1024 somefile.dart
또는
export DART_VM_OPTIONS="--old_gen_heap_size=1024"
http://dartbug.com/13744도를 나열하지 않습니다 --new_gen_heap_size
하지만 dart --print-flags
을 언급하지 플래그해야한다고 생각합니다. 이것이 지원되는지, 어떤 역할을하는지는 알 수 없습니다.
코드에서 볼 수있는 문제는 모든 이미지가 거의 한 번에 다운로드되기 시작하고 수신되는 동안 힙 메모리를 사용한다는 것입니다. 또한 @DannyTupeny의 코드는 변경되지 않습니다.
이전 요청이 완료되었을 때 새 요청 만 호출하거나 파일을받은 동안 스트림을 사용하여 파일을 메모리에 버퍼링하지 않아도 동시에 다운로드 할 수있는 파일 수를 제한 할 수 있습니다 전적으로. 나는 아직이 일을하지 않았으며 적어도 일요일까지 그것을 들여다 볼 시간이 없을 것이다. 그러나 어쩌면 다른 누군가가 그런 시도에 대해 더 많은 것을 제공 할 수있다.
메모리에 전체 파일을 버퍼링하지 않고 들어오는 데이터를 파일로 직접 리디렉션하려면 작동해야하지만 메모리 부족 문제를 재현 할 수 없어 확실히 말할 수는 없습니다.
import 'dart:io' as io;
import 'dart:async' as async;
import 'package:path/path.dart' as path;
import 'package:http/http.dart' as http;
var images = [
"https://c4.staticflickr.com/4/3880/15283361621_bc72a1fb29_z.jpg",
"https://c2.staticflickr.com/4/3923/15101476099_6e1087b76c_h.jpg",
"https://c2.staticflickr.com/4/3899/15288834802_073d2af478_z.jpg",
"https://c4.staticflickr.com/4/3880/15283361621_bc72a1fb29_z.jpg",
"https://c2.staticflickr.com/6/5575/15101869429_fa44a80e87_z.jpg",
"https://c1.staticflickr.com/3/2941/15100232360_03f3631c44_z.jpg",
"https://c1.staticflickr.com/3/2941/15269480156_a28e1c0dbb_b.jpg",
"https://c2.staticflickr.com/4/3907/15103503127_195ffcd5c0_z.jpg",
"https://c2.staticflickr.com/6/5595/15265903986_a3210505f4_c.jpg",
"https://c2.staticflickr.com/6/5567/15100857617_9926f2a189_z.jpg",
"https://c1.staticflickr.com/3/2941/15100542247_6e9c3f13ae_z.jpg",
"https://c2.staticflickr.com/4/3852/15099895539_cf43a904a5_z.jpg"
];
main() {
var futures = <async.Future>[];
images.forEach((url) {
futures.add(new http.Request('GET', Uri.parse(url))
.send().then((response) {
var f = new io.File(path.basename(url));
var sink = f.openWrite();
sink.addStream(response.stream)
.then((_) => sink.close());
}));
});
async.Future.wait(futures) // wait for all image downloads to be finished
.then((_) => print('done'));
}
이것은 내 메모리 문제를 해결하기 위해 완벽하게 작동했습니다. 여러 파일을 동시에 다운로드 할 수 있도록 다시 방문하고 싶습니다. 감사. 나는 새로운 것을 배웠다. –