Objective-C – NSString复制属性内存管理

发布于 2024-12-13 13:58:06 字数 428 浏览 2 评论 0原文

我在类中声明了一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ヅ她的身影、若隐若现 2024-12-20 13:58:06

弄清楚出了什么问题。

我使用了属性名称 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文