内存管理 - 我应该按某些命令为零并释放对象吗?
例如,我创建了一个数组并将一些自定义类放入其中。我应该按一定顺序清零并释放它们吗?如果我把后台ASIHTTPRequests放在一个数组中,如果我先释放该数组,会不会出现泄漏? ARC中也是这样吗?谢谢您的回答。
For example, I created an array and put some custom class into it. Should I nil and release them by a certain order? If I put background ASIHTTPRequests in a array, will there be a leak if I release the array first? Is it the same in ARC? Thank you for your answers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

当您将一个对象添加到 NSArray 时,它会自动保留,然后当您释放该数组时,将向其中的所有对象发送一个
release 信号。那个数组。所以:
等同于:
事实上,当您想要创建对象数组而不关心对这些对象的单独引用时,第二个代码是一种非常常见的做法。
When you add an object to an
NSArray
it is automatically retained, then when yourelease
the array arelease
signal is sent to all the objects in that array. So:Is the same as:
In fact the 2nd code is a very common practice when you want to create an array of objects without taking care of individual references to those objects.