I am creating a deep mutable copy of a dictionary but for some reason am getting a leak. I've tri开发者_如何学JAVAed 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!
My guess is you are retaining one of the objects in the dictionary. What is the number of leaked bytes?
Do you actually release copyOfSectionedDictionaryByFirstLetter
in your dealloc
method?
You will either have to do:
self.copyOfSectionedDictionaryByFirstLetter = nil;
Or:
[copyOfSectionedDictionaryByFirstLetter release];
copyOfSectionedDictionaryByFirstLetter = nil; // Just for good style
I suspect the immediate case to NSMutableDictionary
is confusing the profiler. Try the following:
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);
}
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.
精彩评论