Can anyone explain me self.timer=nil
vs [self.timer invalidate]
?
What exactly happens at the memory location of self.timer
?
First of all, invalidate
is a method of NSTimer
class which can use to stop currently running timer. Where when you assign nil
to any object then, in an ARC environment the variable will release the object.
Its important to stop running timer when you don't longer need, so we write [timer invalidate]
and then we write timer = nil;
to make sure it'll loose its address from memory and later time you can recreate the timer.