title: How to correctly invalidate my timer in NSRunLoop
body: <p>I get information from a server in my app with a secondsToEnd value and I start a counter after I've received this information.</p>
  
  <p>My project contains a scrollview, so to get around locking my timer due to scrolling around I add the timer to the NSRunLoop in the following way:</p>
  
  <pre><code>[[NSRunLoop currentRunLoop] addTimer:timer
                               forMode:NSRunLoopCommonModes];
  </code></pre>
  
  <p>I made a NSTimer property called, how original, timer and this is the whole snippet of my startTimer function:</p>
  
  <pre><code>- (void)startTimer
  {
      if (_timer || [_timer isValid]) [_timer invalidate], _timer = nil, [_timer release];
  
      NSTimer * timer = [[NSTimer alloc] initWithFireDate:[NSDate date]
                                                 interval:1.0
                                                   target:self
                                                 selector:@selector(timer:)
                                                 userInfo:nil
                                                  repeats:YES];
  
      [[NSRunLoop currentRunLoop] addTimer:timer
                                   forMode:NSRunLoopCommonModes];
  
      [self setTimer:timer];
      [timer release];
  }
  </code></pre>
  
  <p>The reason for the check to invalidate in the start method is because after the secondsToEnd value hits 0, I receive a new one and I call startTimer again.</p>
  
  <p>And in my dealloc method I have this:</p>
  
  <pre><code>if (_timer || [_timer isValid]) [_timer invalidate], _timer = nil, [_timer release];
  </code></pre>
  
  <p>But it doesn't get invalidated? What am I doing wrong?</p>