更新到iOS 6.1后,我在AFNetworking框架的AFImageRequestOperation.m和AFHTTPClient.m中收到此警告:
在这个区块中强烈捕获'操作'可能会导致a 保留周期
基于this answer,我可以使用__weak变量在ARC中修复保留周期。它也说
捕获的对象将保留块
有谁知道如何解决这个问题?
感谢。
答案 0 :(得分: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);
}
}];
答案 1 :(得分:0)
好的,这就是问题所在。我一直在从GitHub下载Master branch,现在我尝试下载AFNetworking from here(版本1.1.0),它不再向我显示警告。
我不知道为什么我下载时主分支中没有包含最新的提交,但显然他们在前一段时间内已经解决了这些强大的refs块警告。
始终检查website以查看最新发布的版本或同步GitHub的最新提交:)(我的iOS 6.0应用程序中没有显示任何内容,但Xcode 4.6只是提出了它们)