3
Xcode 4.2에서 iOS 5.0의 새로운 NSLinguisticTagger를 사용하고 있습니다. 이 함수의 목적은 주소록 레코드를 가져 와서 NSString 같이 ABRecordCopyCompositeName과 같은 일종의 복합 이름을 작성하고 동아시아 언어와 헝가리어의 이름 순서를 고려하는 것입니다.).NSLinguisticTagger 메모리 누수
NSString *text = [self getLocalizedFullNameOfRecord:[contacts objectAtIndex:indexPath.section];
- (NSString *) getLocalizedFullNameOfRecord:(ABRecordRef) person
{
NSString *firstName = ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSString *middleName = ABRecordCopyValue(person, kABPersonMiddleNameProperty);
NSString *lastName = ABRecordCopyValue(person, kABPersonLastNameProperty);
NSString *prefix = ABRecordCopyValue(person, kABPersonPrefixProperty);
NSString *suffix = ABRecordCopyValue(person, kABPersonSuffixProperty);
NSString *fullName = @"";
__block BOOL Asian;
// Apologies to all Hungarians who aren't actually Asian
__block NSArray *asianLanguages = [NSArray arrayWithObjects:@"zh-Hant", @"zh-Hans", @"ja", @"ko", @"hu", @"vi", nil];
[firstName enumerateLinguisticTagsInRange:NSMakeRange(0, firstName.length) scheme: NSLinguisticTagSchemeLanguage options: NSLinguisticTaggerOmitWhitespace orthography: nil usingBlock:^(NSString *tag, NSRange tokenRange, NSRange sentenceRange, BOOL *stop){
if ([asianLanguages containsObject:tag])
Asian = YES;
else
Asian = NO;
}];
if(prefix)
fullName = [fullName stringByAppendingFormat:@"%@ ", prefix];
if(Asian && lastName)
fullName = [fullName stringByAppendingFormat:@"%@ ", lastName];
else if(firstName)
fullName = [fullName stringByAppendingFormat:@"%@ ", firstName];
if(middleName)
fullName = [fullName stringByAppendingFormat:@"%@ ", middleName];
if(Asian && firstName)
fullName = [fullName stringByAppendingFormat:@"%@ ", firstName];
else if(lastName)
fullName = [fullName stringByAppendingFormat:@"%@ ", lastName];
if(suffix)
fullName = [fullName stringByAppendingFormat:@"%@", suffix];
[firstName release];
[middleName release];
[lastName release];
[prefix release];
[suffix release];
return fullName;
}
악기 내가 enumerateLinguisticTagger (분명히 아닌 블록 부분)에,이 함수의 모든 반복과 일부 16 ~ 32 바이트를 유출하고 있음을 알려줍니다 : 여기에 기능입니다. NSLinguisticTagger의 온라인 리소스는 클래스 참조 및 단일 자습서로 제한되어 있으므로 어디에서 어떻게 누수를 찾기 시작할 수 있는지 알 수 없습니다.
도와주세요.
+1 유용한 코드입니다. 나는 이것 (http://www.w3.org/International/questions/qa-personal-names)을보고 있었고 내가 어떻게 할 것인지 궁금해했다. & hey-presto, Serendipity to the rescue :-) –