Core Foundation 对象是由 ARC 自动释放的还是我们需要手动内存管理?
Does the Core Foundation objects are automatically released by ARC or do we need manual memory management?
在我的代码中创建了一个 Core Foundation 对象,并且从苹果文档中我了解到
"The life span of a Core Foundation object is determined by its
reference count" https://developer.apple.com/library/mac/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Articles/lifecycle.html
所以我非常怀疑核心基础对象是由ARC释放还是我们需要通过写CFRelease(myobject)
来释放
我正在使用 Xcode 6.4,目前在我的代码中没有使用任何 CFRelease(myobject) 来释放我的 Core Foundation 对象,但我仍然做不到在 xcode 仪器中找到任何 内存泄漏(泄漏)..
所以我的问题是 ARC 是否会负责释放 Core Foundation 对象..??
因为我刚刚遇到这样的说法,
Recall that ARC only deals with Objective-C objects. It doesn’t manage
the retain and release of CoreFoundation objects which are not
Objective-C objects.http://www.raywenderlich.com/23037/how-to-use-instruments-in-xcode
因此,如果有人遇到同样的问题并找到解决方案,请分享...
提前致谢..
您必须调用 CFRelease
来释放 Core Foundation 对象。
The compiler does not automatically manage the lifetimes of Core Foundation objects; you must call CFRetain
and CFRelease
.
或者您可以使用 __bridge_transfer
或 CFBridgingRelease
将 Core Foundation 对象的所有权移动到 Objective-C ARC 对象所有权之下。
__bridge_transfer
or CFBridgingRelease
moves a non-Objective-C pointer to Objective-C and also transfers ownership to ARC.
- ARC is responsible for relinquishing ownership of the object.
所以在下面的情况下,NSString* __strong name
变量拥有 Core Foundation 对象的所有权。当 name = nil;
或 name
变量范围结束时,Core Foundation 对象自动释放。
NSString *name = (NSString *)CFBridgingRelease(ABRecordCopyValue(person, kABPersonFirstNameProperty));
或
NSString *name = (__bridge_transfer NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
在我的代码中创建了一个 Core Foundation 对象,并且从苹果文档中我了解到
"The life span of a Core Foundation object is determined by its reference count" https://developer.apple.com/library/mac/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Articles/lifecycle.html
所以我非常怀疑核心基础对象是由ARC释放还是我们需要通过写CFRelease(myobject)
来释放我正在使用 Xcode 6.4,目前在我的代码中没有使用任何 CFRelease(myobject) 来释放我的 Core Foundation 对象,但我仍然做不到在 xcode 仪器中找到任何 内存泄漏(泄漏)..
所以我的问题是 ARC 是否会负责释放 Core Foundation 对象..??
因为我刚刚遇到这样的说法,
Recall that ARC only deals with Objective-C objects. It doesn’t manage the retain and release of CoreFoundation objects which are not Objective-C objects.http://www.raywenderlich.com/23037/how-to-use-instruments-in-xcode
因此,如果有人遇到同样的问题并找到解决方案,请分享...
提前致谢..
您必须调用 CFRelease
来释放 Core Foundation 对象。
The compiler does not automatically manage the lifetimes of Core Foundation objects; you must call
CFRetain
andCFRelease
.
或者您可以使用 __bridge_transfer
或 CFBridgingRelease
将 Core Foundation 对象的所有权移动到 Objective-C ARC 对象所有权之下。
__bridge_transfer
orCFBridgingRelease
moves a non-Objective-C pointer to Objective-C and also transfers ownership to ARC.
- ARC is responsible for relinquishing ownership of the object.
所以在下面的情况下,NSString* __strong name
变量拥有 Core Foundation 对象的所有权。当 name = nil;
或 name
变量范围结束时,Core Foundation 对象自动释放。
NSString *name = (NSString *)CFBridgingRelease(ABRecordCopyValue(person, kABPersonFirstNameProperty));
或
NSString *name = (__bridge_transfer NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);