NSString retain Count

objective-c

Solution

The compiler is smarter than you.

It sees `@"Hello world"` and thinks "Aha! A constant string!"

It then sees `[[NSString alloc] initWithString:@"Hello world!"]` and thinks "Aha! An immutable object created with a constant string!"

It then collapses both of them down into a single `NSConstantString`, which has a `retainCount` of `UINT_MAX`, so that it can never be released.

Problem

Just couple of days i was working on a project and i have to see what is retain count of a string. But it always return me "2147483647", Why it is so? Check out this code to check it yourself. ``` NSString *str = [[NSString alloc] initWithString:@"Hello World"]; NSLog(@"String Retain Count: %i", [str retainCount]); ``` So my question is why it is not returning 1 like other objects return, why i am getting "2147483647" Thanks in advance.

Original source

Related problems