since every assignment to a variable with a different object increases its retain count and in the dealloc its not always clear how often a variable got assigned a simple [maVar release] might NOT BE SUFFICIENT. So using ALWAYS myVar = nil sets the retain count to zero, and a subsequent [myVar release] will never cause a problem again. (is it actually still required ?)
The only situation when not to do it this way is if myVar is passed OUT then I must not do this, since the value gets destroyed by myVar = nil;
Is my thinking correct? Or could this way of avoiding leaks cause any other problems?
Your thinking is incorrect in quite a lot of ways. These are probably just scratching the surface:
deallocis called when the retain count reaches 0.myVar = nildoes not affect the retain count.myVar = nildestroys only the local pointer value, it does not destroy an object that has been passed out.[myVar release]whenmyVarisnil, but it isn’t useful — it does nothing.It is clear that your grasp of C pointers and Objective-C memory management is a bit lacking. I’d suggest doing some remedial C work before several thorough re-reads of the Memory Management docs.