简体   繁体   English

Objective-C属性

[英]Objective-C property

I'm developing an Iphone app. 我正在开发Iphone应用程序。 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: 然后,在实现文件中,dealloc方法必须放置如下内容:

[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. 它将为我节省1行代码。

Yes, you have to release it. 是的,您必须释放它。 The retain qualifier means that when you set the property, your class will call retain on the NSArray. 保留限定符意味着在设置属性时,您的类将在NSArray上调用保留。 When your class is done, you need to release anything that you have retained, otherwise you have a memory leak. 完成课程后,您需要释放所有保留的内容,否则会发生内存泄漏。

@property NSArray *listData;

will just implicitly declare your accessor and mutator methods for listData, 会隐式声明listData的访问器和mutator方法,

but what about memory management(it's a serious stuff as far as iphone app development is concerned)? 但是内存管理呢(就iPhone应用程序开发而言,这是一个严肃的问题)?

If you going to use it in implementation then you should release it in dealloc method 如果要在实现中使用它,则应在dealloc方法中释放它

also refer Official Apple docs for @property 另请参阅Apple官方文档以获取@property

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM