Unclear about the release of CFDictionaryRef

It is not clear that the consequences of memory management are as follows:

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

Since the CGImageSourceCopyPropertiesAtIndex function has Copy in name, I own CFDictionaryRef and must free it. However, since it is passed to NSDictionary , I cannot call [props release] . What is the right way to treat this?

+4
source share
1 answer

Use CFBridgingRelease to Transfer Ownership in ARC

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

Otherwise, you will need to call CFRelease when you are done with the dictionary.

+7
source

Source: https://habr.com/ru/post/1497047/


All Articles