开发者

Obj-C: A reference or a copy?

Is the product item a copy, or just a reference to the object in the NSArray? Does it need to be released? Considering there is no alloc, I assume there is no need for release, correct?

ProductItem *item = [appDelegate.produ开发者_如何学编程ctTextList objectAtIndex:[indexPath row]];


It is a pointer to the ProductItem class.

You should only release an object if you have done something to increase it's retain count. I.e. alloc/init, copy, or call retain.


It's just a pointer of type ProductItem, so it's not a copy.

Your reference is guaranteed to be valid in the scope of the call to objectAtIndex (it calls autorelease on the object). If you want to keep it around for longer you need to retain and are responsible to release it when you are done with it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜