Where are constant NSStrings allocated?

佐手、 提交于 2020-01-15 09:34:36

问题


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:


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.



来源:https://stackoverflow.com/questions/2768443/where-are-constant-nsstrings-allocated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!