Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

removeObjectAtIndex without releasing the object

I have a mutable array and i would like to arrange it in a nested order upon some criteria. To achieve this I'd like to move certain elements to mutable arrays of another elements, removing them from the main mutable array, but without releasing them. Actually the question is about removing elements from array without releasing them How do i achieve it?

Thanks

like image 339
Nava Carmon Avatar asked Aug 05 '26 04:08

Nava Carmon


2 Answers

You cannot remove an object from an array without the array releasing it. If you want to make sure it sticks around, just retain it yourself first, and release it when you're done. These are pretty cheap operations, so you shouldn't worry too much about it.

like image 94
Ben Gottlieb Avatar answered Aug 07 '26 11:08

Ben Gottlieb


Since you're moving items from one array to another, it would be easier if you first added the object to the new array and then removed it from the original array.

  1. When you add it to the new array it is implicitly retained.
  2. When you remove it from the old array it is implicitly released.

This is faster than retaining it, removing it from the array, adding it to the new array and then releasing it.

like image 28
Abizern Avatar answered Aug 07 '26 12:08

Abizern