2010-06-14 5 views
0

Je reçois la fuite dans cette méthode même le nsstring alloué est libéré.Fuites dans le passage de la demande en utilisant l'URL à NSString, Objective-C

Maintenant, je suis pris stringWithFormat, mais encore, elle manifeste la fuite à "NSData * returnData = ...." ligne

-(BOOL)getTicket:(NSString*)userName passWord:(NSString*)aPassword isLogin:(BOOL)isLogin 
{ 
NSString* [email protected]""; 
if (isLogin == YES) 
{ 

str =[NSString stringWithFormat:@"AGENT=true&LOGIN_ID=%@&PASSWORD=%@",[self _encodeString:userName],[self _encodeString:aPassword]]; 

} 
else if (isLogin == NO) 
{ 
    str =[NSString stringWithFormat:@"AGENT=true&LOGIN_ID=%@&PASSWORD=%@",[self _encodeString:userName],[self _encodeString:aPassword]]; 
} 

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:str] 
                 cachePolicy:NSURLRequestReloadIgnoringCacheData 
                timeoutInterval:25.0]; 
[request setHTTPMethod: @"POST"]; 
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; 
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding]; 

printf("\n returnString in getticket:%s",[returnString UTF8String]); 

NSRange textRange; 

textRange =[returnString rangeOfString:@"TICKET"]; 

if(textRange.location != NSNotFound) 
{ 

    NSArray* splitValues = [returnString componentsSeparatedByString:@"TICKET="]; 
    NSString* str1 = [splitValues objectAtIndex:1]; 
    NSArray* splitValues1 = [str1 componentsSeparatedByString:@"RESULT"]; 
    NSString* ticket1 = [splitValues1 objectAtIndex:0]; 
    self.ticket = ticket1; 

    self.isCorrectLogin = YES; 
    [returnString release]; 
    return YES; 
} 
else 
{ 
    self.isCorrectLogin = NO; 
    [returnString release]; 
    return NO; 
} 

return NO; 

}

S'il vous plaît aidez-moi de ce problème.

Répondre

0

Macbirdie a raison de dire que composer une chaîne en utilisant stringByAppendingString: est horriblement inefficace. Je suggère d'utiliser +stringWithFormat: à la place. En ce qui concerne la fuite, si la fuite correspond à ce que vous dites, cela pourrait être une fuite dans le cadre sous-jacent (et cela pourrait être un faux positif). Publiez le backtrace de l'objet divulgué (qui peut être obtenu à partir de l'instrument Allocations).

+0

Pouvez-vous suggérer comment ajouter en utilisant stringWithFormat pour un –

+0

Je ne suis pas sûr de ce que vous demandez. – bbum