- (void)deallocLove your retainCount, cherish it. It's something you can count on.
NSLog(@"%u", [myView retainCount]); // 3
NSLog(@"%u", [myView retainCount]); // 2
NSLog(@"%u", [myView retainCount]); // 1
myView = nil;
NSLog(@"%u", [myView retainCount]); // 0
self.myView = [[MyView alloc] initWithFrame:frame];
NSLog(@"%u", [self.myView retainCount]); // 2
NSLog(@"%u", [self.myView retainCount]); // 3
UPDATE: Several people have pointed out here and elsewhere that my sample code is wrong. Seems like I fixed a wrong problem in a wrong way and got right results by mistake!
Really appreciate this! Love learning from mistakes, so I've left the "buggy" code here as a reminder. There's nothing wrong with making mistakes - as long as you learn from them. Repeating same old mistakes is waste of time, when there are so many wonderful new ones to discover!
Nevertheless this blog posting was to praise retainCount. Without it I would not have been able to get rid of memory leak, regardless that I fixed wrong problem in wrong way ;-)