开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜