我的项目接近尾声,但在 XCode 中分析我的项目后,它向我表明这一行存在内存泄漏:
以下是相关代码的文字版:
- (void)displayPersonABRecordRef)person
{
NSString* firstName = (__bridge_transfer NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSString *lastName = (__bridge_transfer NSString*)ABRecordCopyValue(person, kABPersonLastNameProperty);
NSMutableString *fullName = [NSString stringWithFormat"%@ %@", firstName, lastName];
//NSLog(@"%@", fullName);
NSString* phoneNum = nil;
ABMultiValueRef phoneNumbers;
phoneNumbers = ABRecordCopyValue(person,
kABPersonPhoneProperty);
if (ABMultiValueGetCount(phoneNumbers) > 0) {
phoneNum = (__bridge_transfer NSString*) ABMultiValueCopyValueAtIndex(phoneNumbers, 0);
} else {
phoneNum = @"Unknown";
}
NSLog(@"First name is %@ and last name is %@", firstName, lastName);
NSLog(@"hone is %@", phoneNum);
phoneNum = [phoneNum stringByReplacingOccurrencesOfString"(" withString""];
phoneNum = [phoneNum stringByReplacingOccurrencesOfString")" withString""];
谁能帮我解决这个问题?我不相信这会造成严重后果,但我不想给苹果一个理由拒绝我的应用程序从商店。谢谢。
最佳...SL
除了 ABRecordCopyValue
的 phoneNumbers
返回值之外,您在任何地方都在使用 __bridge_transfer
。
您需要将phoneNumbers
的所有权转让给ARC或手动释放内存。
更新:仔细研究了这个问题,我不确定您是否可以将所有权转让给 ARC,请参阅 __bridge_transfer and ABRecordCopyValue: and ARC了解更多详情。
添加CFRelease(phoneNumbers)
会手动释放内存。
例如:
NSString* phoneNum = nil;
ABMultiValueRef phoneNumbers;
phoneNumbers = ABRecordCopyValue(person,
kABPersonPhoneProperty);
if (ABMultiValueGetCount(phoneNumbers) > 0) {
phoneNum = (__bridge_transfer NSString*) ABMultiValueCopyValueAtIndex(phoneNumbers, 0);
} else {
phoneNum = @"Unknown";
}
CFRelease(phoneNumbers);
关于ios - XCode 内存泄漏问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14330860/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |