1

楽器は私のコードでリークを示しています: Leak: CFHTTPCookieStorage ->NSData *resultData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; //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);
        }
    });
}

なぜ漏れるのですか?

ここに画像の説明を入力

ここに画像の説明を入力

4

0 に答える 0