With an NSArray of object references, do I explicitly release all objects in the array or just the array itself?

前端 未结 3 549
故里飘歌
故里飘歌 2020-12-08 04:26

My class has an NSArray that is filled with objects. In my dealloc method, can I simply call release on my NSArray, or do I need to iterate the array and release all object

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-08 04:34

    NSArray retains objects when they're added, and releases them when they're removed or the array is deallocated. Keep this in mind, it's this concept of "ownership" that retain/release memory management is built upon. It's the same with the object that owns the array, if it also retained the objects in the array you will need to send them another release message in your dealloc implementation. If not, and if no other objects retained them, they'll be deallocated once the array releases them.

提交回复
热议问题