0
ABMultiValueRef phones = ABRecordCopyValue(ref, kABPersonPhoneProperty);
if ( phones ) {
    for(int i=0;i<ABMultiValueGetCount(phones);i++) {
        NSString* label=(NSString*)ABMultiValueCopyLabelAtIndex(phones, i);
        CFRelease ((CFTypeRef)label);
        CFRelease ((CFTypeRef)label);
    }
}
CFRelease(phones);

Why label can be released twice without any error? but phones cannot. Any memory leak if not release label for twice?

I had run above code successfully in xcode4 simulator 4.3

yuji
  • 16,695
  • 4
  • 63
  • 64
m841lr
  • 1
  • 1
  • try doing this NSLog ([NSString stringWithFormat:@"Label retainCount : %d", [label retainCount]]); after you do CFRelease and see what shows up in your debugger – SayeedHussain May 17 '11 at 15:11
  • The label retainCount is: 2 => 1 => 1 The phones retainCount is: 2 => 1 – m841lr May 18 '11 at 02:20
  • ABAddressBookRef from ABAddressBookCreate() return retainCount is: 1. CFArrayRef from ABAddressBookCopyArrayOfAllPeople() return retainCount is: 1. ABRecordRef from CFArrayGetValueAtIndex() return retainCount is: 2. Any idea? – m841lr May 18 '11 at 03:00

1 Answers1

0

It doesn't matter why this doesn't crash. You absolutely shouldn't be doing it. The contract this function has with you is it returns a value which you must release exactly once. Whatever else it does with this value internally (e.g. caching) that may cause this to not crash is irrelevant.

Lily Ballard
  • 182,031
  • 33
  • 381
  • 347