Releasing Core Foundation object references

rein picture rein · May 15, 2009 · Viewed 8.3k times · Source

Do I need to release a Core Foundation objects to clear up memory? And if so, how?

For example, in the code:

ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef peopleArray = ABAddressBookCopyArrayOfAllPeople(addressBook);

do I need to release peopleArray? What about addressBook?

Answer

Jason Coco picture Jason Coco · May 15, 2009

Yes, in CoreFoundation you have to release anything with Create or Copy in the name. You do this with CFRelease(). In your case, you should be releasing both the array and the address book references.