Eli Ganem
Eli Ganem

Reputation: 1479

Is it possible that NSNumberFormatter leaks memory?

This code leaks when I send a non-numeric string, but doesn't when I send a numeric string. Is it possible that numberFromString: leaks memory when failing and returning nil?

- (BOOL)isNum:(NSString*)str
{
    BOOL ans = YES;
    NSNumberFormatter* nf = [[NSNumberFormatter alloc] init];
    if ([nf numberFromString:str] == nil)
        ans = NO;
    [nf release];
    return ans;
}

Upvotes: 1

Views: 558

Answers (1)

Don Liang
Don Liang

Reputation: 36

Yes, it is possible. It is fine when the parameter only containing letters, such as @"asdf" or only containing numbers, such as @"1234". It will leak, as the Instruments shown, when the parameter is the combination of letters and numbers, such as @"123asdf".

Upvotes: 2

Related Questions