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. ...

Get Cocoa Programming for OS X: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.