I'm talking about methods like -removeAllObjects, -removeLastObject, etc for NSMutableArray. The documentation only says that these methods 'remove' the object from the array. Are the removed objects released?
Yes it does. Any remove invokes the release of the removed NSObject
.
The NSArray
class reference specifies:
Arrays maintain strong references to their contents—in a managed memory environment, each object receives a retain message before its id is added to the array and a release message when it is removed from the array or when the array is deallocated. If you want a collection with different object ownership semantics, consider using CFArray Reference, NSPointerArray, or NSHashTable instead.
Yes, they are released. You can see that the contained object is released by overriding release
in an object you've placed in the container. Call the superclass's release
method and set a breakpoint on it. You'll see that it's released.
I had originally stated that I thought the objects were auto-released. Turns out I believe I'm wrong about that.