开发者

Where are constant NSStrings allocated?

开发者 https://www.devze.com 2022-12-28 22:46 出处:网络
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

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, 开发者_如何学JAVArather than on the heap?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号