1

我正在創建一個字典的深層可變副本,但由於某種原因我正在泄漏。我已經試過這樣:爲什麼使用CFPropertyListCreateDeepCopy時會出現泄漏?

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

這:

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

兩個正在由Interface Builder的泄漏裝置標記。

任何想法?

謝謝!

+0

做了一個構建和分析發現什麼? – 2010-10-13 21:19:37

+0

不...不幸的不是。 – Jonah 2010-10-13 23:32:18

回答

1

我的猜測是要保留在詞典中的對象之一。泄漏的字節數是多少?

+0

這似乎是它。我打算繼續調試幾天以確保。謝謝! – Jonah 2010-10-22 19:22:00

0

你真的在你的dealloc方法中發佈copyOfSectionedDictionaryByFirstLetter嗎?

你將不得不做的事:

self.copyOfSectionedDictionaryByFirstLetter = nil; 

或者:

[copyOfSectionedDictionaryByFirstLetter release]; 
copyOfSectionedDictionaryByFirstLetter = nil; // Just for good style 
+0

是的,我確實發佈它。無論何時在我的appDelegate中調用一個方法,該方法在上面的問題中運行代碼時,都會顯示泄漏。我真的在撓撓我的頭腦。 – Jonah 2010-10-13 23:40:13

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); 
} 
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); 

我想這可能是你的原因泄漏。

相關問題