一直在玩弄工具,但在弄清楚如何解决此内存泄漏方面运气不佳。
首先是代码:
-(NSString *) randomizeHint:(NSString *) wordToShuffle{
NSMutableString * outputstring = [NSMutableString stringWithCapacity:[wordToShuffle length]];
NSMutableSet * usedNumberSet = [NSMutableSet setWithCapacity:[wordToShuffle length]];
for (int i=0; i<[wordToShuffle length]; i++) {
int randomnum = arc4random()%[wordToShuffle length];
while ([usedNumberSet containsObject:[NSNumber numberWithInt:randomnum]]==YES) {
randomnum = arc4random()%[wordToShuffle length];
}
[usedNumberSet addObject:[NSNumber numberWithInt:randomnum]];
[outputstring appendFormat:@"%c",[wordToShuffle characterAtIndex:randomnum]];
}
CCLOG(@"outputstring is:%@",outputstring);
return outputstring;
}
Instruments 给了我以下信息:
Leaked Object = NSCFString, Responsible Library = Foundation, Responsible Frame = -[NSPlaceholderMutableString initWithCapacity:]
有任何想法吗?
提前致谢。