Do removeAllObjects and release of an NSMutableArray both have the same functionality?

后端 未结 1 997
孤独总比滥情好
孤独总比滥情好 2021-01-24 09:26

I have written the following line of code:

NSMutableArray *array=[[NSMutableArray alloc]init];

This allocates some memory. My question is, how

相关标签:
1条回答
  • 2021-01-24 10:03

    When you add an object to the array, the object's retain count will increase by 1. When you remove that object from the array, retain count will decrease by 1 to balance it out. But if you release the array, all objects will automatically receive a release message. So you don't need to call removeAllObjects before releasing the array.

    Technically, these two method are not same. If you call removeAllObjects, the array will become empty and all objects will receive a release message but the array itself is still not released. The array will be released when you call release on it.

    0 讨论(0)
提交回复
热议问题