Objective-C – NSString复制属性内存管理
我在类中声明了一个 NSString
为 @property (nonatomic,copy) NSString *text
。当我想从文本变量获取此数据时,我从另一个类 NSString *text = self.objectInstance.text 调用。进行分析后,Xcode 在行上显示我正在声明文本变量
1。属性返回一个保留计数 +1 的 Objective-C 对象
然后在那行之后
2。对象泄漏:分配的对象在此执行路径中稍后不会被引用,并且保留计数为 +1
我不明白的是,我既不写分配,新,也不复制,因此我不需要释放这个对象?
I have an NSString
declared as @property (nonatomic,copy) NSString *text
in a class. When I want to get this data from the text variable I call from my other class NSString *text = self.objectInstance.text
. After doing an analyze Xcode says on the line that I'm declaring the text variable
1. Property returns an Objective-C object with a +1 retain count
And then after that line
2. Object leaked: allocated object is not referenced later in this execution path and has a retain count of +1
What I don't understand is that I neither write alloc, new, or copy thus I shouldn't need to release this object?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
弄清楚出了什么问题。
我使用了属性名称
newFoo
,这使得编译器认为我返回了一个新对象。所以要提醒自己:理解可可的命名约定。
Figured out what was wrong.
I used the property name
newFoo
which made the compiler think I returned a new object.So note to self: understand cocoa naming conventions.