2 yue1liang1chuan yue1liang1chuan 于 2012.12.05 17:05 提问

解析iPhone应用内存泄露

应用代码如下:
用来过滤和筛选

- (long)personRecord:(ABRecordRef)paramPerson{

    if(paramPerson == nil){

        NSLog(@"The given Person is Null");
    }

    ABMutableMultiValueRef emails = ABRecordCopyValue(paramPerson, kABPersonEmailProperty);
    if(emails == nil){

        return 0;
    }

    NSLog(@"%ld",ABMultiValueGetCount(emails));
    // return (ABMultiValueGetCount(emails));

    return (ABMultiValueGetCount(emails));
}

但是当解析的时候出现:

enter image description here

怎么解决这个Leak?

1个回答

MrsSeven7
MrsSeven7   2012.12.06 09:59
已采纳

你是从ABRecordRef中获得了一份复制的object.释放一下

修改为如下方法:

- (long)personRecord:(ABRecordRef)paramPerson
  {

    if(paramPerson == nil)
    {

        NSLog(@"The given Person is Null");
    }

    ABMutableMultiValueRef emails = ABRecordCopyValue(paramPerson, kABPersonEmailProperty);
    if(emails == nil)
    {

        return 0;
    }

    NSLog(@"%ld",ABMultiValueGetCount(emails));
    // return (ABMultiValueGetCount(emails));

    long count = ABMultiValueGetCount(emails);
     CFRelease(emails);
     return count;
}
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!