views:

1220

answers:

3

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?

+5  A: 

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.

Kriem
You might not get that error immediately if the retainCount > 1 (when some other objects are still retaining it).
rein
@rein - You're right. I edited the answer to a more correct frasing.
Kriem
+3  A: 

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.

rein
+1  A: 

The documentation very clearly states this right at the top of the file:

Like NSArray, instances of NSMutableArray maintain strong references to their contents. If you do not use garbage collection, when you add an object to an array, the object receives a retain message. When an object is removed from a mutable array, it receives a release message. If there are no further references to the object, this means that the object is deallocated. If your program keeps a reference to such an object, the reference will become invalid unless you send the object a retain message before it’s removed from the array.

There is no point documenting this repeatedly for every method.

Mike Abdullah