簡體   English   中英

使用AFNetworking下載文件時出現內存警告

[英]Memory warning while downloading file with AFNetworking

更新:

我寫了一個非常簡單的下載代碼:

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中寫了它,並注釋了所有其他代碼。 內存使用情況仍然相同,並且在不斷增加:

在此處輸入圖片說明

我創建了一個新項目,並在新項目中編寫了完全相同的代碼。 並且內存使用情況是:

在此處輸入圖片說明

哪個好 但是我不明白為什么它在實際項目中與眾不同?

我猜你打開了僵屍模式。 產品->方案->編輯方案
取消選中選項[啟用僵屍對象]

在此處輸入圖片說明

好尷尬 我創建了一個新項目,並復制了相同的代碼,並且它在工作時沒有出現內存警告。 下載操作不會影響內存。 我不明白這個問題。 可能是因為項目設置。

我也一樣 禁用僵屍對象為我工作。

嘗試使用NSOperationQueue手動下載

過來

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM