views:

53

answers:

1

Hi, When i run the instrument i got memory link in below line

NSData *responseData = [NSURLConnection sendSynchronousRequest:theRequest 
    returningResponse:&urlResponse error:&error];

Can some one explain me how to fix this issue,

Thanks Sam.

- (NSString *)sendHttpsReq:(NSString *) urlString {

 // create the request 
 NSString *endResult = nil;

 NSURL *posHostUrl = [NSURL URLWithString:urlString];
 NSURLRequest *theRequest=[NSURLRequest requestWithURL:posHostUrl
             cachePolicy:NSURLCacheStorageAllowed
            timeoutInterval:300.0];
 // create the connection with the request
 // and start loading the data 
 [NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[posHostUrl host]];

 NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];


 if (theConnection) {
  // Create the NSMutableData that will hold
  // the received data
  // receivedData is declared as a method instance elsewhere 


  NSHTTPURLResponse* urlResponse = nil;  
  //NSError *error = [[NSError alloc] init]; 
  NSError *error  = nil;  
  NSData *responseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&urlResponse error:&error];

  endResult = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];  
        //[error release];

 } else{
  //Inform the user that the connection failed.
  NSLog(@"CONNECTION FAILED");
 }

 [theConnection release];

 return [endResult autorelease];
}
+4  A: 

You are in fact starting two NSURLConnections. One asynchronous and one synchronous. This could possible lead to the leak.

First URLConnection is started in the line:

NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

Second URLConnection is started in the line:

NSData *responseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&urlResponse error:&error];

Please make sure you only download your resource once.

tonklon
Thanks for your great help.
Sam