xcode 我什么时候使用 CFRelease?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10203990/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
When do I use CFRelease?
提问by MoonSoo
i'm studying iOS programming.
我正在学习 iOS 编程。
i wrote code that associated an address.
我编写了关联地址的代码。
there's so many methods. like
有这么多方法。喜欢
i'm dividing a group.
我在分组。
here's group1
这是 group1
ABAddressBookCreate();
ABRecordCopyCompositeName(argument);
ABRecordCopyValue(argument1, argument2);
ABRecordCopyValue(argument1, argument2);
ABMultiValueCopyLabelAtIndex(argument1, argument2);
ABMultiValueCopyValueAtIndex(argument1, argument2);
and another one is right here, group2
还有一个就在这里,group2
CFArrayGetCount(argument);
CFArrayGetValueAtIndex(argument1, argument2);
ABMultiValueGetCount(argument);
i know there's so many other methods.
我知道还有很多其他方法。
but i wonder when i use CFRelease method.
但我想知道我什么时候使用 CFRelease 方法。
i think group2's all methods don't do CFRelease
我认为 group2 的所有方法都不会执行 CFRelease
because that contain the word "Get", not allocated.
因为那包含单词“Get”,未分配。
and i think group1's all method have to use CFRelease
我认为 group1 的所有方法都必须使用 CFRelease
because there's a string "copy".
因为有一个字符串“copy”。
i have a book.
我有一本书。
but there's used CFRelease twice.
但有两次使用 CFRelease。
one is release ABAddressBookCreate()
一种是释放 ABAddressBookCreate()
another one is ABAddressBookCopyPeopleWithName.
另一个是 ABAddressBookCopyPeopleWithName。
all of other things don't use CFRelease.
所有其他事情都不使用 CFRelease。
so i wonder when i use CFRelease.
所以我想知道我什么时候使用 CFRelease。
please tell me when i use CFRelease.
请告诉我什么时候使用 CFRelease。
采纳答案by graver
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
如果函数名称包含“Copy”或“Create”,则您拥有该对象,因此您必须在完成对它的工作后释放它。这称为“创建规则”。有关 Core Foundation 内存管理的更多信息,您可以参考 Core Foundation内存管理编程指南
回答by Vignesh
When ever you create a Core Foundation object or become the owner of it you would call CFRelease
.
当你创建一个 Core Foundation 对象或成为它的所有者时,你会调用CFRelease
.
Look at the CFMemory managementdocumentation
看CFMemory管理文档