开发者

Objective-C property

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 p开发者_开发问答ut 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.


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.


@property NSArray *listData;

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜