5 Replies
      Latest reply on May 20, 2020 3:04 AM by eskimo
      Aravind41 Level 1 Level 1 (0 points)

        Implemented post task using NSURLSession and was sending a dectionary in the body of NSMutableURLRequest. The Strings in the dictionary stays in the memory even after the task is done.


        NSError *error;


            NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];

            NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];

            NSURL *url = [NSURL URLWithString:@""];

            NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url




            [request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

            [request addValue:@"application/json" forHTTPHeaderField:@"Accept"];


            [request setHTTPMethod:@"POST"];

            NSMutableDictionary *mapData = [[NSMutableDictionary alloc] initWithObjectsAndKeys: @"darkhorse", @"usrname",


            NSData *postData = [NSJSONSerialization dataWithJSONObject:mapData options:0 error:&error];

            [request setHTTPBody:postData];



            NSURLSessionDataTask *postDataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {




            [postDataTask resume];


        Was able to dump the strings using below commands:

        Step 1 : Connect lldb debugger to device/simulator

        Step 2 : Import => "script import lldb.macosx.heap"

        Step 3 : Search for strings "cstr_refs CSTRING "darkhorse"" after the NSURLSessionDataTask is done