从数组中删除对象
我正在 Objective-C 上开发 iPhone 应用程序 我有带有对象引用的数组 如果我从数组中删除带有对象引用的项目,我是否应该另外释放该对象,或者它将自动从内存中删除?
i'm working on app for iphone on objective-c
i have array with object references
If i remove item with object reference from array should i release this object additionally or it will be removed from memory automatically?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当从数组中删除时,对象会被释放一次。因此,如果您的保留/释放在其他地方正确配对,那么在这种情况下您一定不能释放您的对象。
When removed from array object gets released once. So if your retain/release are paired correctly in other places you must not release your object in this case.
如果
NSArray
(嗯,它是一个NSArray
,不是吗?C 数组不提供所有权管理)是唯一拥有的东西对象 - 也就是说,如果添加的对象是获取autorelease
-d 或者您在添加后显式调用release
- 那么它将在删除时自动清理。任何其他所有权声明仍需要像平常一样release
-d。If the
NSArray
(um, it is anNSArray
, isn't it? C arrays provide no ownership management) is the only thing that owns the object -- that is, if the object added was acquiredautorelease
-d or you explicitly calledrelease
after adding -- then it will be cleaned up automatically on removal. Any other ownership claims will still need to berelease
-d as normal.事实上,您谈论的 NSMutableArray
它会“自动”释放。
所以做
和不做
In fact, your talking about
NSMutableArray
And it does the release 'automatically'.
So do
and don't do