Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用块、ARC泄漏sendSynchronousRequest_Ios_Memory Management_Automatic Ref Counting_Memory Leaks_Block - Fatal编程技术网

Ios 使用块、ARC泄漏sendSynchronousRequest

Ios 使用块、ARC泄漏sendSynchronousRequest,ios,memory-management,automatic-ref-counting,memory-leaks,block,Ios,Memory Management,Automatic Ref Counting,Memory Leaks,Block,仪表显示我的代码有漏洞: 泄漏:CFHTTPCookieStorage ->NSData*resultData=[NSURLConnection sendSynchronousRequest:request returningResponse:&响应错误:&错误]//100.0% 我使用块执行异步下载: NSURL *url = [NSURL URLWithString:user.user_photo]; NSMutableURLRequest* request = [NSMutab

仪表显示我的代码有漏洞: 泄漏:CFHTTPCookieStorage ->
NSData*resultData=[NSURLConnection sendSynchronousRequest:request returningResponse:&响应错误:&错误]//100.0%

我使用块执行异步下载:

   NSURL *url = [NSURL URLWithString:user.user_photo];
   NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url];
   [NSURLConnection asyncRequestSimple:request success:^(NSData *data) {
        user.user_photo_data=data;
        NSLog(@"Image Downloaded");
        dispatch_async(dispatch_get_main_queue(), ^{
           [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
        });     

    } failure:^(NSError *error) {
        NSLog(@"Failed downloading");
    }];
使用类别的异步实现:

NSURLConnection+MyExtensions.h

+ (void)asyncRequestSimple:(NSURLRequest *)request success:(void(^)(NSData* data))successBlock_ failure:(void(^)(NSError *error))failureBlock_;
NSURLConnection+MyExtensions.m

+ (void)asyncRequestSimple:(NSURLRequest *)request success:(void(^)(NSData* data))successBlock_ failure:(void(^)(NSError *error))failureBlock_
{

     [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSURLResponse *response = nil;
        NSError *error = nil;
        NSData *resultData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];//100% leak

        dispatch_sync(dispatch_get_main_queue(), ^{
            [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
        });

        if (error) {
            failureBlock_(error);
        } else {
            successBlock_(resultData);
        }
    });
}
为什么会漏水


已经有一个参数
NSData*data
我更改了名称,泄漏保持不变。我在这里没有看到泄漏。您确定没有将
resultData
泄漏到其他地方吗?可能在您的成功块中?在仪器中,以下行以红色突出显示,标题为100%泄漏:NSData*resultData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];看到这个问题,可能会给你一个线索。