NSString retainCount is 2147483647 [duplicate]

It is 2147483647 because you looked. Don’t look and it will be the value you expect.

Seriously. Don’t call retainCount. Not ever. It is useless.

Why it is such a ridiculous number is because of an implementation detail. @”…” is a constant string. NSString can recognize constant strings and decides that your particular code has no need of a second space consuming copy of a constant immutable string and, thus, returns the already existing constant string.

I.e. a singleton. Of a class whose instances are only ever created by the compiler. For which retain/release/autorelease/retainCount are utterly devoid of meaning.

As for why it is 2147483647, a picture is worth a thousand words. Or, in this case, 31 set bits.
negative one expressed in far too many digits

Leave a Comment