NSURLSession memory leak

后端 未结 3 1128
南方客
南方客 2021-01-15 01:26

Even after invalidate a NSURLSession, running a profile using Instruments, some classes (probably privates) called TubeManager, HTTPConnectionCache and HTTPConnectionCacheDi

3条回答
  •  执念已碎
    2021-01-15 01:38

    finishTasksAndInvalidate called in wrong place... completionHandler is for handling response it has nothing to do with session

    Here is correct code:

    NSURLSessionConfiguration* config = [NSURLSessionConfigurationdefaultSessionConfiguration];
    NSURLSession* session = [NSURLSession sessionWithConfiguration:config];
    NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]];
    NSURLSessionDataTask* sessionDataTask = [session dataTaskWithRequest:request
                                               completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
       // handle response...
    }];
    [sessionDataTask resume];
    [session finishTasksAndInvalidate];
    

提交回复
热议问题