views:

83

answers:

1

Hi Guys,

I have one doubt

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

here some memory is allocated then how can we release this memory, whether using removeAllObjects method or [array release];

Are both have same functionality?

Thank You, Madan Mohan.

+1  A: 

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.

taskinoor
Well then why is my NSMutableArray being released when I call removeAllObjects?
Joe
it should not be released in this case. there might be some other problem. can u post some code so that we can give a try?
taskinoor