Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我知道常量 CStrings 是静态分配的,而不是在堆上。
我还注意到常量 NSStrings 具有无限的保留计数。常量 NSStrings 也是静态分配的,而不是在堆上分配,这是否成立?
常量 NSString 属于 class NSConstantString,因此就像 lisp 中的原子一样;他们闲逛。->NSConstantStrings是静态分配的。也就是说,如果您@"cow"在代码中的两个不同位置使用,它们将引用同一个对象。
NSConstantString
NSConstantStrings
@"cow"
NSConstantStrings甚至有保留计数的原因是因为它们继承自NSObject.
NSObject