views:

59

answers:

1

I understand that constant CStrings are allocated statically, rather than on the heap.

I also noticed that constant NSStrings have an infinite retain count. Does it hold true that constant NSStrings are also allocated statically, rather than on the heap?

+1  A: 

Constant NSStrings are of class NSConstantString, and thus act like atoms in lisp; they hang around. -> NSConstantStrings are allocated statically. That is, if you use @"cow" in two separate places in your code, they will be referencing the very same object.

The reason why NSConstantStrings even have a retain count is because they inherit from NSObject.

Jacob Relkin
Thanks a bunch! That makes a lot of sense.
Andrew Toulouse