应用程序在iPhone 4上崩溃,但在iPhone 3gs上工作正常

时间:2013-05-31 08:41:54

标签: iphone nsstring abaddressbook

应用程序完全崩溃的代码是

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);

然后它崩溃并且没有释放它显示内存泄漏。如何处理?

1 个答案:

答案 0 :(得分:0)

替换

CFRelease(phones);

使用

if(phones){
CFRelease(phones);
}

解决了我的问题。希望它可以帮到某人。

相关问题