代码之家  ›  专栏  ›  技术社区  ›  Jonah

为什么在使用CFPropertyListCreateDeepCopy时会出现泄漏?

  •  1
  • Jonah  · 技术社区  · 14 年前

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

    而这个:

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

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

    有什么想法吗?

    谢谢!

    4 回复  |  直到 14 年前
        1
  •  1
  •   Nick Hingston    14 年前

    我猜你在保留字典里的一个东西。泄漏的字节数是多少?

        2
  •  0
  •   Stefan Arentz    14 年前

    copyOfSectionedDictionaryByFirstLetter 在你的 dealloc 方法?

    你要么必须:

    self.copyOfSectionedDictionaryByFirstLetter = nil;
    

    [copyOfSectionedDictionaryByFirstLetter release];
    copyOfSectionedDictionaryByFirstLetter = nil; // Just for good style
    
        3
  •  0
  •   Jonathan Grynspan    14 年前

    我怀疑眼前的案子 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);
    }
    
        4
  •  0
  •   Deniz Mert Edincik    14 年前

    如果您多次调用下面的部分:

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

    我想这可能是你泄密的原因。