NSMutable array contains an object reference. When you add an object to NSMutableArray, it saves the object. That is, by adding an object to the array, you must free it. When you are done with this object in the array, you can remove the object from the array. After deletion, the object automatically receives a release message. Therefore, you do not need to send another release message. And if you release the array itself, you do not need to send a release message to all objects, since during the release of NSMutableArray it will send a release to all the objects that it contains.
1. alloc NSMutableArray.
2. alloc object1.
3. add object1 to array.
4. release object1.
5. alloc object2.
6. add object2 to array.
7. release object2.
8. add as many objects as needed in this manner.
8. work with object1.
9. remove object1 from array. it will receive a release automatically.
10. release the array. object2 and others will receive a release.
Hope this helps.
source share