I have a method that creates an ABRecordRef, sets its properties and returns the ref.
I'm encountering a crash when I use CFAutoRelease because I need to support iOS <7. how would I go about to properly releasing this?
-(ABRecordRef) myRecord{
ABRecordRef newRecord = ABPersonCreate();
//some setting here
return CFAutoRelease(newRecord); //how to release here?
}
You should be able to build an own autorelease function for Core Foundation objects like this:
With
__autoreleasing
, you force the object to end up in the autorelease pool.For CoreFoundation references, I actually wouldn't release that reference in your
myRecord
method. Instead I would define the interface such that the caller ofmyRecord
owns the reference and is responsible for releasing it.