NSNumber Leaking memory numberWithInt inside a For loop
NSNumber Leaking memory inside a for loop - started occurring at Xcode Instruments version 4.1 on OSX Lion - this is leaking when executed on device profile with instruments. Any ideas appreciated.
int currentActivityScore = [self.activityScore intValue];
int deltaCriteriaScore = [[segmentItemArray objectAtIndex:3] intValue];
int newActivityScore = currentActivityScore + deltaCriteriaScore;
self.activityScore = [NSNumber numberWithInt:newActivityScore];
i tried this code too, still getting a leak!!!
int currentActivityScore = [self.activityScore intValue];
int deltaCriteriaScore = [[segmentItemArray objectAtInde开发者_JS百科x:3] intValue];
int newActivityScore = currentActivityScore + deltaCriteriaScore;
NSNumber *newActivityScoreNumber = [[NSNumber alloc] initWithInt:newActivityScore];
self.activityScore = newActivityScoreNumber;
[newActivityScoreNumber release];
Assuming that activityScore
either retains or copies its values, then I think your code is okay.
It's not unheard of for Instruments to give false-positives (or miss genuine leaks). Consider it a pointer to code to double-check rather than a guarantee of a leak.
NSNumber *newActivityScoreNumber = [NSNumber numberWithInt:newActivityScore];
self.activityScore = newActivityScoreNumber;
So here is NSNumber is autoreleased. you do not need to bother about it.
精彩评论