jackpine / biketag-ios

http://biketag.jackpine.me
1 stars 1 forks source link

invalidate countown timer #1

Closed michaelkirk closed 9 years ago

michaelkirk commented 9 years ago

per @jmoody's advice, invalidate recurring timers so that their target can be GC'd.

See more: http://antonholmquist.com/blog/why-you-really-shouldnt-create-repeating-nstimers-in-init-or-viewdidload/

jmoody commented 9 years ago

I have a protocol for this in LJS:

Example

- (void) startAndRetainRepeatingTimers {
  [self stopAndReleaseRepeatingTimers];
  _timer = [NSTimer scheduledTimerWithTimeInterval:0.2
                                            target:self
                                          selector:@selector(handleRepeatingTimerEvent:)
                                          userInfo:nil
                                           repeats:YES];
}

- (void) stopAndReleaseRepeatingTimers {
  if (_timer != nil) {
    [_timer invalidate];
    _timer = nil;
  }
}
michaelkirk commented 9 years ago

done with #50. Thanks for the advice @jmoody!