I have a method that gets data from the data manager. It looks something like this:
- (void)GetData {
NSArray *anArray = [datamanager GetData]; // GetData returns an autoreleased array
self.MyDataArray = anArray;
}
MyDataArray is declared as a property (nonatomic, retain)
My question is, the function datamanager GetData gets changed elsewhere in code, returning different values for anArray when GetData is called. I’m confused at the line self.MyDataArray = anArray. Cause as far as I know, this would retain anArray the first time, then the method GetData gets called again, then a different anArray gets retained, and so forth. So is this a memory leak? If so, what do I need to do in order to not have memory leaking? thanks.
There is no memory leak because MyDataArray, being declared as retain, has an implementation that releases any reference it hold before retaining the new reference when you do
self.MyDataArray = anArray.