问题描述
- 解析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)); }
但是当解析的时候出现:
怎么解决这个Leak?
解决方案
你是从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;
}
时间: 2024-11-05 20:36:02