Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top