使用AFNetworking下载文件时出现内存警告 [英] Memory warning while downloading file with AFNetworking

查看:103
本文介绍了使用AFNetworking下载文件时出现内存警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:

我写了一个非常简单的下载代码:

I wrote a very simple download code:

NSArray       *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString  *documentsDirectory = [paths objectAtIndex:0];

NSURLRequest* request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://xxxx.s3.amazonaws.com/products/ipad/xxxx.mp4"]];
for(int i=0; i<4; i++){
    NSString  *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,[NSString stringWithFormat:@"xxxx%d.mp4",i]];
    AFDownloadRequestOperation* operation = [[AFDownloadRequestOperation alloc] initWithRequest:request targetPath:filePath shouldResume:YES];
    operation.outputStream = [NSOutputStream outputStreamToFileAtPath:filePath append:NO];
    [operation setShouldOverwrite:YES];
    [operation setProgressiveDownloadProgressBlock:^(AFDownloadRequestOperation *operation, NSInteger bytesRead, long long totalBytesRead, long long totalBytesExpected, long long totalBytesReadForFile, long long totalBytesExpectedToReadForFile) {
        NSLog(@"%f", ( totalBytesRead / (float)totalBytesExpected));
    }];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"finished");
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(error.description);
    }];
    [[NSOperationQueue mainQueue] addOperation:operation];
}

我在我的项目viewDidLoad中写了它,以注释掉所有其他代码.内存使用率仍然相同,并且在不断提高:

I wrote it in my projects viewDidLoad commenting out all other codes. Memory usage is still the same and increasing:

我创建了一个新项目,并在新项目中编写了完全相同的代码.内存使用情况是:

I created a new project, and I wrote exactly the same code in the new project. And the memory usage is:

哪个好.但是我不明白为什么它在实际项目中与众不同?

Which is good. But I don't understand why it is different in the real project?

推荐答案

这很尴尬.我创建了一个新项目,并复制了相同的代码,并且它在工作时没有出现内存警告.下载操作不会影响内存.我不明白这个问题.可能是因为项目设置.

This is awkward. I created a new project, and copy the same code, and it is working without memory warning. Download operation doesn't effect the memory. I didn't understand the problem. Maybe because of the project settings.

这篇关于使用AFNetworking下载文件时出现内存警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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