Is this how you are supposed to use a CFMutableDictionaryRef with ARC?
CFMutableDictionaryRef myDict = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
NSString *key = @"someKey";
NSNumber *value = [NSNumber numberWithInt: 1];
//ARC doesn't handle retains with CF objects so I have to specify CFBridgingRetain when setting the value
CFDictionarySetValue(myDict, (__bridge void *)key, CFBridgingRetain(value));
id dictValue = (id)CFDictionaryGetValue(myDict, (__bridge void *)key);
//the value is removed but not released in any way so I have to call CFBridgingRelease next
CFDictionaryRemoveValue(myDict, (__bridge void *)key);
CFBridgingRelease(dictValue);//no leak
Don’t use
CFBridgingRetainandCFBridgingReleasehere at all. Also, you need to use__bridgewhen casting the result ofCFDictionaryGetValue.There is no need for
CFBridgingRetainbecause the dictionary will retain the value anyway. And if you don’t callCFBridgingRetain, you don’t need to balance it with a release later.Anyway, this is all much simpler if you just create an
NSMutableDictionaryand then, if you need aCFMutableDictionary, cast it:Note that a
CFBridgingRetaincan be balanced by aCFRelease; you don’t have to useCFBridgingReleaseunless you need theidthat it returns. Similarly, you can balance aCFRetainwith aCFBridgingRelease.