不清楚发布CFDictionaryRef

dav*_*idm 5 cocoa core-foundation ios automatic-ref-counting

我不清楚以下内存管理含义:

NSDictionary* props = (__bridge NSDictionary*) CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL);
Run Code Online (Sandbox Code Playgroud)

由于该CGImageSourceCopyPropertiesAtIndex函数在名称中具有Copy,因此我拥有CFDictionaryRef并且必须将其释放.但是,既然它被投了一个NSDictionary,我就不能打电话了[props release].什么是对待这个的正确方法?

Wai*_*ain 8

使用CFBridgingRelease的所有权转移到ARC

CFDictionaryRef cfDict = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL);
NSDictionary *dict = (NSDictionary *)CFBridgingRelease(cfDict);
Run Code Online (Sandbox Code Playgroud)

否则你需要在CFRelease完成字典后调用.