【问题标题】:Unclear about releasing CFDictionaryRef不清楚释放 CFDictionaryRef
【发布时间】:2013-08-14 14:30:49
【问题描述】:

我不清楚以下内容对内存管理的影响:

NSDictionary* props = (__bridge NSDictionary*) CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL);

由于CGImageSourceCopyPropertiesAtIndex 函数名称中有Copy,我拥有CFDictionaryRef 并且必须释放它。但是,由于它被转换为NSDictionary,我不能调用[props release]。什么是正确的治疗方法?

【问题讨论】:

    标签: ios cocoa automatic-ref-counting core-foundation


    【解决方案1】:

    使用CFBridgingRelease将所有权转移到ARC

    CFDictionaryRef cfDict = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL);
    NSDictionary *dict = (NSDictionary *)CFBridgingRelease(cfDict);
    

    否则,您需要在完成字典后致电CFRelease

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-24
      • 2013-02-28
      • 2020-01-29
      • 1970-01-01
      • 1970-01-01
      • 2019-02-08
      相关资源
      最近更新 更多