0

im building an app which grabs all the contacts from iPhone book and filter it my names having only emails. i use the following function for that (filtering with names having email address)

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

When analysed I'm geting potential leak

enter image description here

how can i resolve this Leak ....????

4

2 回答 2

2

你没有释放对象,这就是它导致内存泄漏的原因。试试这个代码。这将修复泄漏并在正确的位置释放对象。希望这对你有帮助

              CFRelease(emails);
于 2012-12-04T13:12:26.820 回答
1

您正在从 获取该对象的副本ABRecordRef。所以你需要释放它。

改变你的方法,比如;

- (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;
}
于 2012-12-04T13:16:27.800 回答