2011-04-23 8 views
0

다음 코드에서 누수가 발생합니다.아이폰 앱의 메모리 누수 문제

  cell.lblNoOfReplay.text=[NSString stringWithFormat:@"0 Replies. %@",(NSString *)CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault, (CFStringRef)[[NSString stringWithFormat:@"Last message on %@",[BabbleVilleAppDelegate dateByAddingHours:Babbleoffset withDate:[[arrayPMMainList objectAtIndex:[indexPath section]] objectForKey:@"datetime"]]] stringByReplacingOccurrencesOfString:@"+" withString:@" "], CFSTR(""), kCFStringEncodingUTF8)]; 

여기에 내가 어떤 문자열을 할당 havent 한 해달라고하지만 난 메모리를 확인하면 위의 라인에 약간의 누수가 누수. 아마도 kCFAllocatorDefault 때문일 수 있습니다. 따라서 같은 문제를 겪어 왔고, 저를 도와주세요.

감사 Mrugen

+2

몬스터 코드 줄에는 많은 것들이 있습니다. 잠정적 인 변수를 조금씩 나누면 좋습니다. 그러면 누출을 줄이는 데 도움이됩니다. –

답변

5

예, 문자열을 할당했다. 핵심 기반 개체는 Create rule 다음에 있습니다. 이름에 Create 또는 Copy가 포함 된 함수를 통해 얻은 개체는 호출자가 소유하며 호출자가 해당 개체를 사용한 후에 릴리스해야합니다. 여러 조각과 중간 변수에 그 라인을 깨는 고려, 또한

CFStringRef s = CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault, (CFStringRef)[[NSString stringWithFormat:@"Last message on %@",[BabbleVilleAppDelegate dateByAddingHours:Babbleoffset withDate:[[arrayPMMainList objectAtIndex:[indexPath section]] objectForKey:@"datetime"]]] stringByReplacingOccurrencesOfString:@"+" withString:@" "], CFSTR(""), kCFStringEncodingUTF8); 
cell.lblNoOfReplay.text=[NSString stringWithFormat:@"0 Replies. %@", (NSString *)s]; 
CFRelease(s); 

:

은 당신의 코드를 변경

. 그 미래의 자아를 포함하여 그 코드를 보는 다른 사람들은 당신에게 감사 할 것입니다.