2013-01-15 41 views
2

我接近我的項目結束,儘管它表明我的XCode分析我的項目有在該行內存泄漏後:XCode的內存泄漏問題

http://i.imgur.com/uTkbA.png

這裏是相關代碼的文字版:

- (void)displayPerson:(ABRecordRef)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(@"Phone is %@", phoneNum); 

    phoneNum = [phoneNum stringByReplacingOccurrencesOfString:@"(" withString:@""]; 
    phoneNum = [phoneNum stringByReplacingOccurrencesOfString:@")" withString:@""]; 

任何人都可以幫我解決這個問題嗎?我不認爲這是癱瘓的,但我不想讓蘋果有理由拒絕我的應用程序從商店。謝謝。

最佳... SL

回答

4

您正在使用__bridge_transfer無處不在,除了從ABRecordCopyValuephoneNumbers返回值。

您需要將phoneNumbers的所有權轉讓給ARC或手動釋放內存。

UPDATE:看了這個問題後,我不確定您可以將所有權轉讓給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); 
+0

非常感謝你的快速和正確的反應。一旦網站允許我將這個標記爲正確的...... – Skyler