3

更新到 iOS 6.1 后,我在 AFNetworking 框架的 AFImageRequestOperation.m 和 AFHTTPClient.m 中收到此警告:

在此块中强烈捕获“操作”可能会导致保留周期

基于这个答案,我可以通过使用 __weak 变量来修复 ARC 中的保留周期。它也说

块将被捕获的对象保留

有谁知道如何解决这个问题?

谢谢。

4

2 回答 2

4

我们很幸运,XCode 4.6 显示了一个警告来避免这个问题它可以通过提供一个弱引用来解决

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);
    }
}];
于 2013-02-02T18:04:55.197 回答
0

好的,这就是问题所在。我一直在从 GitHub 下载Master 分支,现在我尝试从这里下载 AFNetworking (版本 1.1.0),它不再向我显示警告。

我不明白为什么我下载时最新的提交没有包含在 master 分支中,但很明显他们已经在之前的块警告中解决了这些强 refs。

始终检查网站以查看最新发布的版本或从 GitHub 同步最新提交 :) (它没有在我的 iOS 6.0 应用程序中显示任何内容,但 Xcode 4.6 刚刚显示它们)

于 2013-02-03T03:56:17.203 回答