Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When do I use CFRelease?

i'm studying iOS programming.

i wrote code that associated an address.

there's so many methods. like

i'm dividing a group.

here's group1

ABAddressBookCreate();
ABRecordCopyCompositeName(argument);
ABRecordCopyValue(argument1, argument2);
ABRecordCopyValue(argument1, argument2);
ABMultiValueCopyLabelAtIndex(argument1, argument2);
ABMultiValueCopyValueAtIndex(argument1, argument2);

and another one is right here, group2

CFArrayGetCount(argument);
CFArrayGetValueAtIndex(argument1, argument2);
ABMultiValueGetCount(argument);

i know there's so many other methods.

but i wonder when i use CFRelease method.

i think group2's all methods don't do CFRelease

because that contain the word "Get", not allocated.

and i think group1's all method have to use CFRelease

because there's a string "copy".

i have a book.

but there's used CFRelease twice.

one is release ABAddressBookCreate()

another one is ABAddressBookCopyPeopleWithName.

all of other things don't use CFRelease.

so i wonder when i use CFRelease.

please tell me when i use CFRelease.

like image 531
MoonSoo Avatar asked Apr 18 '12 06:04

MoonSoo


1 Answers

If the function name contains "Copy" or "Create", then you own the object, so you must release it when you finish your work with it. This is called "The Create Rule". For more information on Memory management for Core Foundation, you can refer to Memory Management Programming Guide for Core Foundation

like image 69
graver Avatar answered Oct 15 '22 22:10

graver