I am noticing a memory leak around the NSURLSession
in my code.
Below is the code that uses NSURLSession
in my app:
-(void)createWithUserId:(NSString*)userId andAccountNumber:(NSString*)accountNumber
{
NSURL *url = [NSURL URLWithString:[WebServiceUtility getCreateBatchURLWithBaseURL:self.baseURL]];
NSURLSession *session = [NSURLSession sessionWithConfiguration:[WebServiceUtility getSessionConfigurationWithRequestHeader:(NSDictionary*)self.requestHeader andTimeout:self.requestTimeout]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
request.HTTPMethod = kCMDCPOSTMethod;
NSDictionary *dictionary = self.requestBody;
NSError *error = nil;
NSData *data = [NSJSONSerialization dataWithJSONObject:dictionary
options:kNilOptions error:&error];
if (!error) {
NSURLSessionUploadTask *uploadTask = [session uploadTaskWithRequest:request
fromData:data completionHandler:^(NSData *data,NSURLResponse *response,NSError *error) {
if([[WebServiceUtility getStatusCodeForResponse:response] isEqualToString:kCMDCStatusCode_200] && data)
{
NSMutableDictionary *json = [WebServiceUtility dictionaryFromData:data];
[self.delegate createdWithResults:json];
}
else
{
NSMutableDictionary *json=[[NSMutableDictionary alloc]init];
[json setObject:kCMDCServerError_1 forKey:kCMDCServerError];
[json setObject:[WebServiceUtility getStatusCodeForResponse:response] forKey:kCMDCStatusCode];
[self.delegate createdWithResults:json];
}
}];
[uploadTask resume];
}
}