How to release memory created from CFStringTokenizerCreate?
I use CFRelease to release the CFStringTokenizerRef obtained from CFStringTokenizerCreate call. But instruments is reporting memory leak at around this area. Am I missing something?
CFStringTokenizerRef tokenRef = CFStringTokenizerCreate(NULL, (CFStringRef)contents, CFRangeMake(0, contents.length), kCFStringTokenizerUnitWordBoundary, 开发者_如何学JAVA NULL); CFStringTokenizerTokenType tokenType; // leak reported here while ((tokenType = CFStringTokenizerAdvanceToNextToken(tokenRef)) != kCFStringTokenizerTokenNone) } CFRelease(tokenRef);
CFStringTokenizerCreate follows the Create Rule. So you are calling as expected.
There seems to be a missing brace after the while, this the CFRelease is not in the same scope. Is it a copy/paste error ?
精彩评论