Remove objects from NSArray

automatic-ref-counting, ios, nsarray, nsmutablearray, release

Solution

You can just do this:

array = newArray;

This will cause `array` to be released. When this `NSArray` gets deallocated, all contained objects will be released, too.

Problem

I have a project with ARC. I have an `NSArray` whit some object inside. At certain point I need to change the object in the array. Whit a `NSMutableArray` I'll do : ``` [array removeAllObjects]; ``` and I'm sure that this method release all object contained in the array. But with an NSArray I can't do that! So, my question is: if I set array to `nil` and then re-initialize it, the old object contained in the array are really released from memory ? ``` array = nil; array = [[NSArray alloc] initWithArray:newArray]; ``` Or I need to use `NSMutableArray` ?

Original source