So some where i have a leak which is related to deleting an object under certain circumstances.
Premise: - I have an NSMutableArray of Tree objects (a Tree object knows how to draw itself). - I have a reference pointer (Tree *selected) which basically points to whatever tree i last touched. - Note that the *selected pointer is a weak reference.
Ok, so far so good.
Problem: The leak arises when i delete a Tree. From the list i make sure the tree being deleted is releasing everything internally before removing it from the array (removing it from the array should automatically call release on it).
What i tried: I noticed that my Tree *selected pointer is being assigned the touched tree via the self property:
self.selected = tree;
...and by doing this i know that it is being retained. So what i tried to do was call:
[self.selected release];
I called this right after the tree is removed from the array. ...but at which point it crashes essentially stating it was already released.
Question: Why am i getting this error message? I removed it from the array, however my self.selected pointer still has a retained count, thus shouldn't i be releasing it?
Perhaps I should set it to nil after the removal process? Or, perhaps I should set it to autorelease BEFORE the removal process?