If I have a helper method thats adds object to an array (NSMutableArray) in my custom class, would it make sense to do either:
- somehow auto-detect whether the incoming object has been already autoreleased? then if not release it after adding it to the array?
- in dealloc iterate through all objects in the array and somehow check they don’t need to be released, and then after this release the array itself?
the concern I have is when I have to dealloc my custom class, including the array, how do I know the status of the objects within the array?
It should be the responsibility of code calling your helper method to release the objects (through autorelease or normal release) after passing them to your function. The objects being passed to you will be retained for your use by putting them in your array. When you release your array in your dealloc, all the objects in that array will be released. Make sense?
I.e. you don’t need to do anything special–just add the objects to your array.