问题描述
我了解常量CString是静态分配的,而不是在堆上分配的。
I understand that constant CStrings are allocated statically, rather than on the heap.
我还注意到常量NSString具有无限的保留计数。
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?
推荐答案
常量NSString属于类<$,这是否成立? c $ c> NSConstantString ,因此就像Lisp中的原子一样;他们闲逛。 -> NSConstantStrings
是静态分配的。也就是说,如果您使用 @ cow
在代码中的两个不同位置,它们将引用同一对象。
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.
NSConstantStrings
的原因保留计数是因为它们是从 NSObject
继承的。
The reason why NSConstantStrings
even have a retain count is because they inherit from NSObject
.
这篇关于常量NSStrings在哪里分配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!