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 t开发者_JS百科hem. Actually the question is about removing elements from array without releasing them How do i achieve it?
Thanks
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.
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.
- When you add it to the new array it is implicitly retained.
- 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.
精彩评论