开发者

NSString Memory Leak

- (NSString*) getProjectCoreName
{
    return [NSString stringWithFormat:@"%@_%ld", kTLProject, sProjectCores++];
}

Instruments is telling me 32 bytes is leaking from the above function. The string is used as a key in a static NSMutableDictionary:

[dictionary setObject:instance forKey:name];

This dictionary is 开发者_如何学JAVAnever released during the course of the program. Is this a leak? This is a MacOS application.

The dictionary is defined statically:

static NSMutableDictionary *dictionary = nil;

Then later:

if(dictionary == nil){
    dictionary = [NSMutableDictionary dictionaryWithCapacity:5];
    [dictionary retain];
};


This function itself does not contain a memory leak. stringWithFormat returns an autoreleased object and so are you. If there is a leak it must be somewhere else.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜