How do I autorelease a CFMutableDictionary?
I’m creating it like this:
self.mappingByMediatedObject = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
And in dealloc:
self.mappingByMediatedObject = nil;
CoreFoundation doesn’t have a notion of autorelease– that’s a Cocoa-level construct. However, for the objects that are “toll-free” bridged across worlds like strings and the collection classes, you can get the same result by casting the CF reference to its corresponding Cocoa reference, and sending it the
-autoreleasemessage, like this:In your case, though, you might not really want to use autorelease here, because you’re not handing back the reference for a Cocoa caller. Why not be a little more explicit around your allocation instead and just releasing it after setting it, like this: