【发布时间】:2013-10-02 14:03:04
【问题描述】:
我正在从 UIGridViewCells 下载电影文件。我的代码是:
NSMutableURLRequest* rq = [[APIClient sharedClient] requestWithMethod:@"GET" path:[[self item] downloadUrl] parameters:nil];
[rq setTimeoutInterval:5000];
_downloadOperation = [[AFHTTPRequestOperation alloc] initWithRequest:rq] ;
_downloadOperation.outputStream = [NSOutputStream outputStreamToFileAtPath:[[self item] localUrl] append:NO];
__weak typeof(self) weakSelf = self;
[_downloadOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Successfully downloaded file to %@", [weakSelf.item localUrl]);
[Helper saveItemDownloaded:weakSelf.item.productId];
weakSelf.isDownloading = NO;
[weakSelf.progressOverlayView removeFromSuperview];
[weakSelf setUserInteractionEnabled:YES];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
[weakSelf.progressOverlayView removeFromSuperview];
[weakSelf setUserInteractionEnabled:YES];
weakSelf.isDownloading = NO;
}];
[_downloadOperation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
float progress = totalBytesRead / (float)totalBytesExpectedToRead;
weakSelf.progressOverlayView.progress = progress;
}];
[[NSOperationQueue mainQueue] addOperation:_downloadOperation];
而ItemCell中的属性是:
@property (nonatomic, retain) AFHTTPRequestOperation *downloadOperation;
在 1-2 次成功下载 (20mb) 后,我收到内存警告。每次下载使用的内存都会增加,下载完成后不会减少。
来自仪器:
【问题讨论】:
-
你是在for循环里面做这一切吗?
-
对于下载操作,是的。但是我发送了一个播放电影的列表。
标签: ios memory-management afnetworking-2