ARC Retain Cycle appears after updating to iOS 6.1

After upgrading to iOS 6.1, I get this warning in AFImageRequestOperation.m and AFHTTPClient.m from AFNetworking framework:

Capturing an "operation" strongly in this block will probably result in a save loop

Based on this answer , I can fix the save loop in ARC with __weak variables. It also says

The block will be saved by the captured object

Does anyone know how to solve this?

Thank.

+3


source to share


2 answers


OK there was a problem. I kept on downloading the master branch from GitHub and now when I tried to download AFNetworking from here (version 1.1.0) it no longer shows me a warning.

I don't understand why the latest commits were not included in the main branch when I checked in, but it is clear that they solved those strong links in the block warnings earlier.



Always check the site to see the latest released version or sync the latest commit with GitHub :) (This didn't show anything in my iOS 6.0 app, but Xcode 4.6 just picked them up)

0


source


We are lucky that XCode 4.6 shows a warning to avoid this problem It can be solved by providing a weak link



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);
    }
}];

      

+4


source







All Articles