Objective-C 属性
我正在开发一个 iPhone 应用程序。我从一本关于声明属性的书中读到如下内容:
@property (nonatomic, retain) NSArray *listData;
然后在实现文件中,dealloc 方法必须放置类似以下内容:
[listData release];
我想知道我是否声明为是否
@property NSArray *listData;
必须释放它?它会为我节省 1 行代码。
I'm developing an Iphone app. I read from a book about declaring a property like below:
@property (nonatomic, retain) NSArray *listData;
Then in the implementation file, dealloc method, must put something like:
[listData release];
I wonder if I declare as
@property NSArray *listData;
do I have to release it? It'll save 1 line of code for me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,你必须释放它。保留限定符意味着当您设置属性时,您的类将在 NSArray 上调用保留。当你的课程完成后,你需要释放你保留的任何东西,否则你就会发生内存泄漏。
Yes, you have to release it. The retain qualifier means that when you set the property, your class will call retain on the NSArray. When your class is done, you need to release anything that you have retained, otherwise you have a memory leak.
只会隐式声明 listData 的访问器和修改器方法,
但是内存管理怎么样(就 iphone 应用程序开发而言,这是一个严肃的事情)?
如果您要在实现中使用它,那么您应该在 dealloc 方法中释放它,
另请参阅 @property 的官方 Apple 文档
will just implicitly declare your accessor and mutator methods for listData,
but what about memory management(it's a serious stuff as far as iphone app development is concerned)?
If you going to use it in implementation then you should release it in dealloc method
also refer Official Apple docs for @property