I have some confusion about when to use the self keyword during ivars assignment, should I use it when I'm trying to assign certain value to ivar or only when I'm trying to access the ivar?
Besides, if I do retainCount on an ivar after its assignment without using self, it prints a count of 1 assuming it was already alloc & init. But if I use self it gives me retain count of 2.
Example Code:
Titles = [[NSMutableDictionary alloc] init];
NSLog(@"Titles before assignment: %d", [Titles retainCount]); // print 1
Titles = anotherDictionary; NSLog(@"Titles after assignment: %d", [Titles retainCount]); // print 1
self.Titles = anotherDictionary; NSLog(@"Titles after assignment: %d", [Titles retainCount]); // print 2
Should not I use self during assignment or when should I use? Any help would be really very appreciated as this situation is giving me a lots of doubts that my ivars are not being released the proper way.
Thanks, Mohsen
Edit: I have another related issue to my above question, should I use self to assign singleton classes properties?