ABMultiValueCopyValueAtIndex 允许释放两次吗?
ABMultiValueRef phones = ABRecordCopyValue(ref, kABPersonPhoneProperty);
if ( phones ) {
for(int i=0;i<ABMultiValueGetCount(phones);i++) {
NSString* label=(NSString*)ABMultiValueCopyLabelAtIndex(phones, i);
CFRelease ((CFTypeRef)label);
CFRelease ((CFTypeRef)label);
}
}
CFRelease(phones);
为什么label可以释放两次而没有错误?但手机不能。 两次不释放label会导致内存泄漏吗?
我已经在 xcode4 模拟器 4.3 中成功运行了上面的代码
ABMultiValueRef phones = ABRecordCopyValue(ref, kABPersonPhoneProperty);
if ( phones ) {
for(int i=0;i<ABMultiValueGetCount(phones);i++) {
NSString* label=(NSString*)ABMultiValueCopyLabelAtIndex(phones, i);
CFRelease ((CFTypeRef)label);
CFRelease ((CFTypeRef)label);
}
}
CFRelease(phones);
Why label can be released twice without any error? but phones cannot.
Any memory leak if not release label for twice?
I had run above code successfully in xcode4 simulator 4.3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么这不会崩溃并不重要。你绝对不应该这样做。该函数与您之间的契约是它返回一个值,您必须释放该值一次。无论它在内部对这个值做了什么(例如缓存),都可能导致它不崩溃,这是无关紧要的。
It doesn't matter why this doesn't crash. You absolutely shouldn't be doing it. The contract this function has with you is it returns a value which you must release exactly once. Whatever else it does with this value internally (e.g. caching) that may cause this to not crash is irrelevant.