Chris Hill
Chris Hill

Reputation: 1924

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 never 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];
};

Upvotes: 1

Views: 942

Answers (1)

albertamg
albertamg

Reputation: 28572

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.

Upvotes: 2

Related Questions