I have a headache problem, I just create a method:
-(void) main{ for (int i = 0; i< 100;i++) { [self getPhoneOfContact:i]; } } -(void)getPhoneOfContact:(NSInteger)id_contact { ABRecordRef record = ABAddressBookGetPersonWithRecordID(addressBook,id_contact); CFTypeRef ref1; ref1 = ABRecordCopyValue(record,kABPersonPhoneProperty); CFRelease(record); CFRelease(ref1); }
I think that the memory will approximate the constants, because I have copied the memory of the memory, but in fact it is still increasing for each cycle i; who can explain this to me :( thanks!
Your code is incorrect. A call to ABAddressBookGetPersonWithRecordID follows the Core Foundation "Get Rule". This means that you do not have ownership of the return value, and you do not need to release it.
See Core Foundation - Memory Management
, ABAddressBookGetPersonWithRecordID / ABRecordCopyValue , , . , , . .
ABAddressBookGetPersonWithRecordID
ABRecordCopyValue
:
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // do computation [pool release];
"reset" ?
, , XCode Instruments , - , Memory Leaks , :)
, , , ...
// 1. alloc and return a record address to record ABRecordRef record = ABAddressBookGetPersonWithRecordID(addressBook,id_contact); // 2. alloc and return the default CFTypeRef to ref1 CFTypeRef ref1; // 3. copy and return the value of kABPersonPhoneProperty ref1 = ABRecordCopyValue(record,kABPersonPhoneProperty); // release 1 CFRelease(record); // release 3 CFRelease(ref1);
, 2 . , CFTypeRef ref1 = nil ?
CFTypeRef ref1 = nil
Does it even work for you? Actual retrieval of information? This is what I use to extract kABPersonPhoneProperty from records.
ABMutableMultiValueRef multi = ABRecordCopyValue(person, kABPersonPhoneProperty); for (CFIndex i = 0; i < ABMultiValueGetCount(multi); i++) { CFStringRef phoneNumberLabel = ABMultiValueCopyLabelAtIndex(multi, i); CFStringRef phoneNumber = ABMultiValueCopyValueAtIndex(multi, i); // Do stuff with the info. CFRelease(phoneNumberLabel); CFRelease(phoneNumber); } CFRelease(multi);