Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ARC Retain Cycle appears after updating to iOS 6.1

After updating to iOS 6.1, I'm getting this warning in AFImageRequestOperation.m and AFHTTPClient.m from AFNetworking framework:

Capturing 'operation' strongly in this block is likely to lead to a retain cycle

Based on this answer, I can fix a retain cycle in ARC by using __weak variables. It is also says

Block will be retained by the captured object

Does anyone know how to solve this?

Thanks.

like image 618
Maziyar Avatar asked Dec 30 '25 10:12

Maziyar


1 Answers

We are fortunate that XCode 4.6 is showing a warning to avoid this problem It can be solved by providing a weak reference

AFImageRequestOperation *requestOperation = [[AFImageRequestOperation alloc] initWithRequest:urlRequest];

**__weak AFImageRequestOperation *tempRequestOperation = requestOperation;**

[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
    if (success) {
        UIImage *image = responseObject;
        if (imageProcessingBlock) {
            dispatch_async(image_request_operation_processing_queue(), ^(void) {
                UIImage *processedImage = imageProcessingBlock(image);

                dispatch_async(**tempRequestOperation**.successCallbackQueue ?: dispatch_get_main_queue(), ^(void) {
                    success(operation.request, operation.response, processedImage);
                });
            });
        } else {
            success(operation.request, operation.response, image);
        }
    }
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    if (failure) {
        failure(operation.request, operation.response, error);
    }
}];
like image 95
Harini Avatar answered Jan 02 '26 03:01

Harini