Obj-C:参考还是副本?
产品项是副本,还是只是对 NSArray 中对象的引用?是否需要释放?考虑到没有分配,我认为不需要释放,对吗?
ProductItem *item = [appDelegate.productTextList objectAtIndex:[indexPath row]];
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.productTextList objectAtIndex:[indexPath row]];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它是指向
ProductItem
类的指针。如果您采取了一些措施来增加对象的保留计数,则应该仅释放该对象。即
alloc/init
、copy
或调用retain
。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 callretain
.它只是一个
ProductItem
类型的指针,所以它不是一个副本。您的引用保证在对 objectAtIndex 的调用范围内有效(它在对象上调用 autorelease)。如果您想将其保留更长时间,则需要保留它并负责在使用完毕后将其释放。
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.