현재 아래 코드로 여러 이미지를 다운로드 중입니다. 내 앱에서 50,000 개 이상의 이미지를 다운로드해야합니다. 메모리 사용량이 600MB에 도달하면 메모리 부족으로 인해 응용 프로그램이 다운됩니다.50,000 이미지 이상을 다운로드해야합니다.
10K 이미지를 다운로드 할 때 작동합니다. 그러나 서버에서 20K 이미지를 다운로드하려고 할 때 메모리 압력으로 인해 9-10K 이미지 응용 프로그램이 다운되는 경우.
또한 메모리 누수를 찾기 위해 계기를 사용해 보지만 메모리 누수가 없습니다. 디버그 세션에서
(때 다운로드 20K 이미지) :메모리 소비 : 5백~6백메가바이트와 자사의 충돌 후.
CPU 사용 : 130 -160 %
당신이 내 코드에서 뭘 잘못했는지 좀 도와 주시겠습니까? 난 당신이 응용 프로그램이 많은 이미지를 다운로드하지 제안합니다
- (void)Downloadimages:(NSMutableArray *)aMutArray
{
//newchange
SDImageCache *imageCache = [SDImageCache sharedImageCache];
[imageCache clearMemory];
[imageCache clearDisk];
// NSLog(@"DocumentsDirectory Path : %@", DocumentsDirectory);
NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] init];
static AFURLSessionManager *sessionManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
sessionManager = [[AFURLSessionManager alloc] initWithSessionConfiguration:sessionConfiguration];
});
__block int iCounter = 0;
for (NSInteger aIndex = 0; aIndex < aMutArray.count; aIndex++)
{
NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString:aMutArray[aIndex]] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:(aMutArray.count * 120)];
// urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:aMutArray[aIndex]] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:100];
//NSLog(@"%@",urlRequest);
// [urlRequest setTimeoutInterval:(aMutArray.count * 120)];
NSURLSessionDownloadTask *downloadTask = [sessionManager downloadTaskWithRequest:req progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response)
{
return [NSURL fileURLWithPath:[DocumentsDirectory stringByAppendingPathComponent:urlRequest.URL.lastPathComponent]];
}
completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error)
{
iCounter ++;
if (!error){
// NSLog(@"(%ld) SUCCESS : %@",(long)aIndex, aMutArray[aIndex]);
}
else
{
NSLog(@"(%ld) ERROR : %@",(long)aIndex, aMutArray[aIndex]);
// [CommonMethod DeleteImageWithName:filePath.lastPathComponent];
}
[labelSyncProducts setText:[NSString stringWithFormat:@"Syncing Images %d of %lu", iCounter, (unsigned long)aMutArray.count]];
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantPast]];
if (aMutArray.count == iCounter)
{
[self controlsEnableDisable:true];
}
}];
[downloadTask resume];
}
}
50K 이미지를 앱에 다운로드 하시겠습니까? 그것은 미친 사람입니다. 나는 대안을 찾을 것을 제안한다. 50k 이미지가 앱 성능을 망칠 것입니다 –
페이징 같은 페이징을 사용하지 마시고 어떤 이미지가 유용합니다. – Tech
@Dev_Tandel 해당 프로젝트 요구 사항 –