应用程序真正崩溃的代码是
NSString *phone, *phone_personal, *phone_business;
for(CFIndex i = 0; i < ABMultiValueGetCount(phones); i++) {
mobileLabel = (NSString*)ABMultiValueCopyLabelAtIndex(phones, i);
if([mobileLabel isEqualToString:(NSString *)kABPersonPhoneMainLabel]){
phone = [(NSString*)ABMultiValueCopyValueAtIndex(phones, i) retain];
}
else{
phone=@"(null)";
}
if([mobileLabel isEqualToString:(NSString *)kABPersonPhoneMobileLabel]){
phone_personal = [(NSString*)ABMultiValueCopyValueAtIndex(phones, i)retain];
}
else{
phone_personal=@"(null)";
}
if ([mobileLabel isEqualToString:(NSString*)kABPersonPhoneIPhoneLabel]){
phone_business = [(NSString*)ABMultiValueCopyValueAtIndex(phones, i)retain];
}
else{
phone_business=@"(null)";
}
[mobileLabel release];
}
CFRelease(phones);
首先我从地址簿中读取所有的电话号码,然后将电话号码添加到数组arrayofnumbersandmeamsil。
if (!([phone isEqualToString:@"(null)"]|| phone == nil || phone.length ==0)){
[arrayofnumbersandmeamsil addObject:phone];
}
if (!([phone_personal isEqualToString:@"(null)"]|| phone_personal == nil || phone_personal.length ==0)) {
[arrayofnumbersandmeamsil addObject:phone_personal];
}
if (!([phone_business isEqualToString:@"(null)"]|| phone_business == nil || phone_business.length ==0)) {
[arrayofnumbersandmeamsil addObject:phone_business];
}
我的问题是我的应用程序在iPhone 4上崩溃,在iPhone 3gs上运行良好,都有iOS 6.1.3。我知道这个问题与phone_personal phone_business的初始化有关。
问题是关于内存释放。当我释放mobileLabel使用
[mobileLabel release];
和使用
释放手机CFRelease(phones);
然后它崩溃而不释放它显示内存泄漏。如何处理呢?
替代
CFRelease(phones);
if(phones){
CFRelease(phones);
}
解决我的问题。