[英]App crashes on iPhone 4 but works fine on iPhone3gs
The code where the app exactly crashes is 该应用程序确切崩溃的代码是
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);
First I am reading the all the phone numbers from the addressbook and then adds the phone numbers to the array arrayofnumbersandmeamsil . 首先,我从通讯录中读取所有电话号码,然后将电话号码添加到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];
}
My problem is my app is crashing on iPhone 4 and working fine on iPhone 3gs both have iOS 6.1.3. 我的问题是我的应用程序在iPhone 4上崩溃了,在iPhone 3gs都运行iOS 6.1.3的情况下工作正常。 I know the issue is related to the initialization of phone,phone_personal,phone_business.
我知道问题与phone,phone_personal,phone_business的初始化有关。
Issue is regarding the memory release. 问题与内存释放有关。 when i release mobileLabel using
当我使用以下方式释放mobileLabel时
[mobileLabel release];
and release phones using 并使用释放手机
CFRelease(phones);
Then it crashes and without releasing it shows the memory leak. 然后它崩溃了,没有释放它表明内存泄漏。 How to handle this ?
如何处理呢?
replacing 更换
CFRelease(phones);
With 用
if(phones){
CFRelease(phones);
}
Solved my issue. 解决了我的问题。 Hope it helps someone.
希望它可以帮助某人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.