I have a piece of code that the ARC converter turned into this…
// firstRange is a NSRange obviously
// test is an NSString * passed in as parameter to the method
NSRange range = NSMakeRange(firstRange.location, (lastRange.location - firstRange.location) + lastRange.length);
NSString *sentence = [text substringWithRange:range];
// OK, now chop it up with the better parser
CFRange allTextRange = CFRangeMake(0, [sentence length]);
CFLocaleRef locale = CFLocaleCopyCurrent();
CFStringTokenizerRef tokenizer = CFStringTokenizerCreate(kCFAllocatorDefault,
(__bridge CFStringRef) sentence,
allTextRange,
kCFStringTokenizerUnitWord,
locale);
I call this A LOT and I suspect that it leaks somehow. Is that CFStringTokenizerCreate call kosher? I am especially suspicious of the __bridge call. Do I create an intermediate that I have to manually release or some such evil?
You need to
CFReleasethetokenizerandlocaleor else they will leak.This falls under Core Foundation Ownership Policy and has nothing to do with ARC.
The
__bridgecast tells ARC that no ownership transfer is done forsentenceinCFStringTokenizerCreatecall. So that is Ok.You can test for memory leaks with Xcode’s static analyser and profiler.