1

我正在创建字典的深层可变副本,但由于某种原因出现泄漏。我试过这个:

NSMutableDictionary *mutableCopy = (NSMutableDictionary *)CFPropertyListCreateDeepCopy(kCFAllocatorDefault, sectionedDictionaryByFirstLetter, kCFPropertyListMutableContainers);
self.copyOfSectionedDictionaryByFirstLetter = mutableCopy;
CFRelease(mutableCopy);

和这个:

copyOfSectionedDictionaryByFirstLetter = (NSMutableDictionary *)CFPropertyListCreateDeepCopy(kCFAllocatorDefault, sectionedDictionaryByFirstLetter, kCFPropertyListMutableContainers);

两者都被接口生成器的泄漏设备标记。

有任何想法吗?

谢谢!

4

4 回答 4

1

我的猜测是您保留了字典中的一个对象。泄露的字节数是多少?

于 2010-10-22T13:01:24.750 回答
0

你真的copyOfSectionedDictionaryByFirstLetter在你的dealloc方法中释放吗?

您要么必须这样做:

self.copyOfSectionedDictionaryByFirstLetter = nil;

或者:

[copyOfSectionedDictionaryByFirstLetter release];
copyOfSectionedDictionaryByFirstLetter = nil; // Just for good style
于 2010-10-13T21:16:26.327 回答
0

If you are calling part below multiple times:

NSMutableDictionary *mutableCopy = (NSMutableDictionary *)CFPropertyListCreateDeepCopy(kCFAllocatorDefault, sectionedDictionaryByFirstLetter, kCFPropertyListMutableContainers);
self.copyOfSectionedDictionaryByFirstLetter = mutableCopy;
CFRelease(mutableCopy);

you should change it to:

NSMutableDictionary *mutableCopy = (NSMutableDictionary *)CFPropertyListCreateDeepCopy(kCFAllocatorDefault, sectionedDictionaryByFirstLetter, kCFPropertyListMutableContainers);
[self.copyOfSectionedDictionaryByFirstLetter release];
self.copyOfSectionedDictionaryByFirstLetter = mutableCopy;
CFRelease(mutableCopy);

I guess that can be your reason for the leak.

于 2010-10-24T14:45:10.173 回答
0

我怀疑直接的情况NSMutableDictionary是使分析器感到困惑。尝试以下操作:

CFMutableDictionaryRef mutableCopy = CFPropertyListCreateDeepCopy(kCFAllocatorDefault, sectionedDictionaryByFirstLetter, kCFPropertyListMutableContainers);
if (mutableCopy) {
    // NOTE: you MUST check that CFPropertyListCreateDeepCopy() did not return NULL.
    // It can return NULL at any time, and then passing that NULL to CFRelease() will crash your app.
    self.copyOfSectionedDictionaryByFirstLetter = (NSMutableDictionary *)mutableCopy;
    CFRelease(mutableCopy);
}
于 2010-10-23T17:49:58.647 回答