Is memory still expanding when using CFRelease for ABRecordCopyValue?

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!

+5
source share
4 answers

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

+5

, ABAddressBookGetPersonWithRecordID / ABRecordCopyValue , , . , , . .

:

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// do computation
[pool release];

"reset" ?

, , XCode Instruments , - , Memory Leaks , :)

0

, , , ...

 // 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 ?

0
source

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);
0
source

All Articles