I have the following scenario:
class1
methodA
NSMutableArray *myArray=[[NSMutableArray alloc]init];
[class2 methodB:myArray];
[myArray release];
...
class2
methodB:(NSMutableArray) myArray{
[class3 methodB:myArray];
}
...
class3
methodC:(NSMutableArray) myArray{
manipulate contents of myArray...
}
...
Is it appropriate to release myArray JUST in methodA or should I release it in each methodB and methodC? I want all three methods to have access to the same contents, i.e., it is the same array being accessed in each method.
If you do not own
myArrayinmethodBormethodC(that is you have not retained in that methods) then don’t release in those methods. You own the array only in first method viaalloc, so you release it only inmethodA. So your approach is correct.