Leaks in passing the request using URL at NSString, Objective-C
I getting the leak in this method even the allocated nsstring is released.
Now I am taken stringWithFormat, but still it is showing the leak at "NSData *returnData=...." line
-(BOOL)getTicket:(NSString*)userName passWord:(NSString*)aPassword isLogin:(BOOL)isLogin
{
NSString* str=@"";
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 
       开发者_如何学JAVA                                            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;
}
Please help me out of this problem.
Macbirdie is correct in that composing a string using stringByAppendingString: is horribly inefficient.  I would suggest using +stringWithFormat: instead.
As for the leak, if the leak is where you say it is, then it might be a leak in the underlying framework (and it might be a false positive). Post the backtrace of the leaked object (which can be had from the Allocations instrument).
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论