O'Reilly logo

Cocoa Programming for OS X: The Big Nerd Ranch Guide by Aaron Hillegass, Adam Preble, Nate Chandler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

NSTimer and Strong/Weak References

When a timer is scheduled, the run loop keeps a strong reference to the timer. We would say that the run loop “owns” the timer. Thus it is unnecessary to keep a strong reference to it yourself.

In some cases, such as your Dice application, it is unnecessary to keep any sort of reference at all. Generally speaking NSTimer references are only needed in order to invalidate the timer or to determine whether it is still running. In this application, since the timer is invalidated when it is fired for the last time, and because the action method’s sender is the timer, no timer property is needed.

However, at times you will need to invalidate a timer before it fires, and in that case you will need a reference. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required