简体   繁体   中英

AFNetworking downloading multiple files memory footprint

I'm using ARC and I'm have an issue downloading multiple files (10000+) in my app when using AFNetworking. I'm creating each AFHTTPRequest and then queuing them to be executed. When I run this using instruments, I can see the memory usage increasing and increasing until the all the files have been downloaded, only then is all the memory released. This survives on the simulator, but crashes when running on an iOS device.

Below is a sample code of what i'm doing

for (int i = 0; i < NUM_OF_FILES_TO_DOWNLOAD; i++) {
    _imageCounter++;
    [self downloadFile:i];
}

- (void)downloadFile:(NSUInteger)num
{    
    NSString *fileURL = @"file/%d/", num];
    NSURLRequest *url = [self.httpClient requestWithMethod:@"GET" path:fileURL parameters:nil];

    AFHTTPRequestOperation *requestOperation = [_httpClient HTTPRequestOperationWithRequest:url success:^(AFHTTPRequestOperation *operation, id responseObject) {
     ...
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
     ...
    }];

    [_httpClient enqueueHTTPRequestOperation:requestOperation];    
}

It appears that the files( responseObject ) aren't being released after the operation success block is executed and that is what is continually increasing the memory footprint? Is this correct? Am I using the AFNetworking and the operationQueue as intended?

你可能想在你的for循环中放一个@autoreleasepool。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM