Утечка памяти идентифицирована для NSURLConnection - PullRequest
2 голосов
/ 27 июля 2010

Когда я запускаю инструмент, я получаю ссылку на память в строке ниже

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

Может кто-нибудь объяснить мне, как решить эту проблему,

Спасибо Сэм.

- (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];
}

1 Ответ

4 голосов
/ 27 июля 2010

Вы фактически запускаете два NSURLConnections.Один асинхронный и один синхронный.Это может привести к утечке.

Первая URLConnection запущена в строке:

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

Вторая URLConnection запущена в строке:

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

Пожалуйста, сделайтеуверен, что вы загружаете свой ресурс только один раз.

...