1

辞書の深く変更可能なコピーを作成していますが、何らかの理由でリークが発生しています。私はこれを試しました:

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

この:

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

両方とも、InterfaceBuilderのリークデバイスによってフラグが立てられています。

何か案は?

ありがとう!

4

4 に答える 4

1

私の推測では、あなたは辞書にあるオブジェクトの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

直接のケース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 に答える
0

以下の部分を複数回呼び出す場合:

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

次のように変更する必要があります。

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

それがリークの理由かもしれないと思います。

于 2010-10-24T14:45:10.173 に答える