应用程序完全崩溃的代码是
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。我知道这个问题与电话、电话个人、电话业务的初始化有关。
问题与内存释放有关。当我使用释放 mobileLabel
[mobileLabel release];
并释放手机使用
CFRelease(phones);
然后它崩溃并且没有释放它显示内存泄漏。如何处理?