I have to used NSOperations to download images (and save to disk), but memory didn't released! After some googling i found hook, that my operations in the retention cycle. I tried to fix my code, but problem is still here.
Can anyone find the error in my code?
There is my code:
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
queue.maxConcurrentOperationCount = 10;
__block NSBlockOperation *completionOperation = [NSBlockOperation blockOperationWithBlock:^{
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
complection(YES); // this is a method's callback actually
}];
}];
for (NSURL* url in imagesURLs) {
__weak NSBlockOperation *downdloadOperation = [NSBlockOperation blockOperationWithBlock:^{
NSData *imageData = [NSData dataWithContentsOfURL:url];
if (imageData) {
[[RuzaImageDiskHandler instance] saveImage:imageData forUrlKey:url];
}
}];
[completionOperation addDependency:downdloadOperation];
}
[queue addOperations:completionOperation.dependencies waitUntilFinished:NO];
[queue addOperation:completionOperation];