Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will -replaceObjectAtIndex:withObject: of NSMutableArray release the old object that's replaced by a new one?

The documentation doesn't say anything about that. When an old object is "removed" and a new one comes into it's place, then what happens with the old one? Do I have to release it by myself?

like image 368
Thanks Avatar asked Dec 21 '25 02:12

Thanks


2 Answers

No, you don't have to release it by yourself.

You might get an error if the replaced object has a retain count equal to 0.

The new object is retained. The old object is released.

like image 115
Kriem Avatar answered Dec 22 '25 17:12

Kriem


You do not have to release it.

You didn't perform an alloc, copy or retain on it and thus are not responsible for the memory - with this the documentation is quite clear.

I wouldn't expect Apple to document the memory management procedures for each method in the SDK unless it violates the memory management rules they have already set up. If the documentation doesn't say anything you can assume the default rules apply.

like image 35
rein Avatar answered Dec 22 '25 16:12

rein



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!