views:

164

answers:

1

The following leaks:

CFStringRef labelName = ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(aMultiRef, indexPath.row));
    cell.textLabel.text = (NSString *)labelName;
    CFRelease(labelName);

Wondering if there a way to rewrite it so it doesn't leak without breaking out & assigning ABMultiValueCopyLabelAtIndex(aMultiRef, indexPath.row) to a CFStringRef that I then need to manually CFRelease 2 lines later? Of course, it's not a big deal to do just that...I'm just curious.

Edit: Would CFAutoRelease work? see my comment below

+2  A: 

Because of Copy/Get semantics you are required to release anything that comes out of an API with Copy in it. ABMultiValueCopyLabelAtIndex meets that requirement, so unfortunately you'll need to acquire this reference and release it later on.

fbrereto
What about `CFAutoRelease`? could `CFStringRef labelName = ABAddressBookCopyLocalizedLabel(CFAutoRelease(ABMultiValueCopyLabelAtIndex(aMultiRef, indexPath.row)));` work?
Meltemi
There is no `CFAutoRelease`; you should store references to anything you create temporarily in a local variable and `CFRelease` it when finish.
rpetrich