MoonSoo
MoonSoo

Reputation: 385

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.

Upvotes: 14

Views: 9516

Answers (2)

graver
graver

Reputation: 15213

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

Upvotes: 14

Vignesh
Vignesh

Reputation: 10251

When ever you create a Core Foundation object or become the owner of it you would call CFRelease.

Look at the CFMemory management documentation

Upvotes: 4

Related Questions