From 31758693335b36b4f3cc9a03119dda861eb09f41 Mon Sep 17 00:00:00 2001 From: Nick Forge Date: Wed, 21 Nov 2012 15:46:19 +1100 Subject: [PATCH] Fixed retain cycles in AFImageRequestOperation.m and AFHTTPClient.m caused by strong references within blocks These retain cycles started showing up as compiler warnings after upgrading to Xcode 4.6DP --- AFNetworking/AFHTTPClient.m | 3 ++- AFNetworking/AFImageRequestOperation.m | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index 96a7060..e3439da 100644 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -566,8 +566,9 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) {} for (AFHTTPRequestOperation *operation in operations) { AFCompletionBlock originalCompletionBlock = [operation.completionBlock copy]; + __weak AFHTTPRequestOperation *weakOperation = operation; operation.completionBlock = ^{ - dispatch_queue_t queue = operation.successCallbackQueue ?: dispatch_get_main_queue(); + dispatch_queue_t queue = weakOperation.successCallbackQueue ?: dispatch_get_main_queue(); dispatch_group_async(dispatchGroup, queue, ^{ if (originalCompletionBlock) { originalCompletionBlock(); diff --git a/AFNetworking/AFImageRequestOperation.m b/AFNetworking/AFImageRequestOperation.m index f4f724a..5c24c79 100644 --- a/AFNetworking/AFImageRequestOperation.m +++ b/AFNetworking/AFImageRequestOperation.m @@ -82,7 +82,7 @@ static dispatch_queue_t image_request_operation_processing_queue() { dispatch_async(image_request_operation_processing_queue(), ^(void) { UIImage *processedImage = imageProcessingBlock(image); - dispatch_async(requestOperation.successCallbackQueue ?: dispatch_get_main_queue(), ^(void) { + dispatch_async(operation.successCallbackQueue ?: dispatch_get_main_queue(), ^(void) { success(operation.request, operation.response, processedImage); }); }); @@ -113,7 +113,7 @@ static dispatch_queue_t image_request_operation_processing_queue() { dispatch_async(image_request_operation_processing_queue(), ^(void) { NSImage *processedImage = imageProcessingBlock(image); - dispatch_async(requestOperation.successCallbackQueue ?: dispatch_get_main_queue(), ^(void) { + dispatch_async(operation.successCallbackQueue ?: dispatch_get_main_queue(), ^(void) { success(operation.request, operation.response, processedImage); }); });