为什么使用 CFPropertyListCreateDeepCopy 时会出现泄漏?
我正在创建字典的深度可变副本,但由于某种原因出现泄漏。我已经尝试过这个:
NSMutableDictionary *mutableCopy = (NSMutableDictionary *)CFPropertyListCreateDeepCopy(kCFAllocatorDefault, sectionedDictionaryByFirstLetter, kCFPropertyListMutableContainers);
self.copyOfSectionedDictionaryByFirstLetter = mutableCopy;
CFRelease(mutableCopy);
还有这个:
copyOfSectionedDictionaryByFirstLetter = (NSMutableDictionary *)CFPropertyListCreateDeepCopy(kCFAllocatorDefault, sectionedDictionaryByFirstLetter, kCFPropertyListMutableContainers);
两者都被界面生成器的泄漏设备标记。
有什么想法吗?
谢谢!
I am creating a deep mutable copy of a dictionary but for some reason am getting a leak. I've tried this:
NSMutableDictionary *mutableCopy = (NSMutableDictionary *)CFPropertyListCreateDeepCopy(kCFAllocatorDefault, sectionedDictionaryByFirstLetter, kCFPropertyListMutableContainers);
self.copyOfSectionedDictionaryByFirstLetter = mutableCopy;
CFRelease(mutableCopy);
And this:
copyOfSectionedDictionaryByFirstLetter = (NSMutableDictionary *)CFPropertyListCreateDeepCopy(kCFAllocatorDefault, sectionedDictionaryByFirstLetter, kCFPropertyListMutableContainers);
Both are being flagged by interface builder's leaks device.
Any ideas?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我的猜测是你正在保留字典中的对象之一。泄漏的字节数是多少?
My guess is you are retaining one of the objects in the dictionary. What is the number of leaked bytes?
你真的在你的dealloc方法中释放了copyOfSectionedDictionaryByFirstLetter吗?
您必须执行以下操作:
或:
Do you actually release
copyOfSectionedDictionaryByFirstLetter
in yourdealloc
method?You will either have to do:
Or:
我怀疑 NSMutableDictionary 的直接情况使分析器感到困惑。请尝试以下操作:
I suspect the immediate case to
NSMutableDictionary
is confusing the profiler. Try the following:如果您多次调用下面的部分:
您应该将其更改为:
我想这可能是泄漏的原因。
If you are calling part below multiple times:
you should change it to:
I guess that can be your reason for the leak.