开发者

Obj-C: A reference or a copy?

开发者 https://www.devze.com 2022-12-22 02:26 出处:网络
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?

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

精彩评论

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