Iphone 找出内存泄漏?
我是iphone应用程序的新手。现在这是我的第一个应用程序,应用程序已安装但未运行? 我写的这段代码显示内存泄漏。请找出。提前感谢Iphone 找出内存泄漏?,iphone,objective-c,ios4,abaddressbook,Iphone,Objective C,Ios4,Abaddressbook,我是iphone应用程序的新手。现在这是我的第一个应用程序,应用程序已安装但未运行? 我写的这段代码显示内存泄漏。请找出。提前感谢 ABRecordRef ref = CFArrayGetValueAtIndex(all, i); CFStringRef *firstName = (CFStringRef *)ABRecordCopyValue(ref, kABPersonFirstNameProperty); NSLog(@"Name %@", firstName); contact.str
ABRecordRef ref = CFArrayGetValueAtIndex(all, i);
CFStringRef *firstName = (CFStringRef *)ABRecordCopyValue(ref, kABPersonFirstNameProperty);
NSLog(@"Name %@", firstName);
contact.strFirstName = (NSString*)firstName;
CFStringRef *lastName = (CFStringRef *)ABRecordCopyValue(ref, kABPersonLastNameProperty);
NSLog(@"Name %@", lastName);
contact.strLastName = (NSString*)lastName;
contact.contactName = [NSString stringWithFormat:@"%@ %@",(NSString *)firstName,lastName];
NSLog(@"Name %@", contact.contactName);
ABMutableMultiValueRef phoneNumbers = ABRecordCopyValue(ref, kABPersonPhoneProperty);
for(CFIndex j = 0; j < ABMultiValueGetCount(phoneNumbers); j++)
{
CFStringRef phoneNumberRef = ABMultiValueCopyValueAtIndex(phoneNumbers, j);
NSString *phoneNumber = (NSString *) phoneNumberRef;
contact.strMobileNo = phoneNumber;
NSLog(@"phoneNO is %@", phoneNumber);
CFRelease(phoneNumberRef);
}
ABMultiValueRef emails = ABRecordCopyValue(ref, kABPersonEmailProperty);
for(CFIndex k = 0; k < ABMultiValueGetCount(emails); k++)
{
CFStringRef emailRef = ABMultiValueCopyValueAtIndex(emails, k);
NSString *mailid = (NSString *) emailRef;
contact.strMail = mailid;
NSLog(@"Email is %@", mailid);
CFRelease(emailRef);
}
CFRelease(emails);
CFRelease(phoneNumbers);
ABRecordRef=CFArrayGetValueAtIndex(全部,i);
CFStringRef*firstName=(CFStringRef*)ABRecordCopyValue(ref,KabbersonfirstNameProperty);
NSLog(@“Name%@”,firstName);
contact.strFirstName=(NSString*)firstName;
CFStringRef*lastName=(CFStringRef*)ABRecordCopyValue(ref,kABPersonLastNameProperty);
NSLog(@“Name%@”,lastName);
contact.strLastName=(NSString*)lastName;
contact.contactName=[NSString stringWithFormat:@“%@%@”,(NSString*)firstName,lastName];
NSLog(@“Name%@”,contact.contactName);
ABMutableMultiValueRef phoneNumbers=ABRecordCopyValue(ref,kABPersonPhoneProperty);
对于(CFIndex j=0;j
您正在对firstName和lastName使用ABRecordCopyValue
,这意味着您需要cf同时发布这些内容。您需要添加:
CFRelease(firstName);
CFRelease(lastName);
CFRelease是一条路要走(正如@Joe和@jamapag已经回答的那样)。。我只想补充一点,XCode没有几个很好的特性,比如cmd+shift+a为你提供了一个静态内存分析器。。您还可以使用run->run w/performance工具,然后使用分配或泄漏动态分析内存管理 为什么不使用xcode的内存泄漏查找器呢?我用过,但没有bcz我是这项技术的新手谢谢你的建议。我会在Chehai检查一下,我发布的这两个firstName和lastName应用程序崩溃了……所以请帮我……。你需要在行NSLog(@“Name%@”,contact.contactName)后添加CFRelease
代码>你在哪里发布的?海,我发布的这两个名字和姓氏应用程序崩溃了……所以请帮助我。。。。。。。