Search code examples
objective-ccore-foundationnsmutableset

toll-free bridged objects, retain and release


I'm currently looking at a NSMutableSet created by the function CFSetCreateMutable(). The documentation states that the return value of CFSetCreateMutable() is toll-free bridged, meaning that I can simply cast it into a NSMutableSet. Does this mean that sending it the release message is perfectly valid? Am I always safe to assume that I can always treat such objects as if they were alloc'ed via an NS-class?


Solution

  • Just imagine that CFSetCreateMutable() is equivalent to [[NSMutableSet alloc] init] in that you have to release the object after you are done with it. If you are using ARC, you can cast a CFMutableSet to an NSMutableSet using a bridged cast: (__bridge_transfer NSMutableSet *)theCFSet. This will tell ARC that it is responsible for releasing the set after it goes out of scope.