Archives / Search ›

Pester 1.0 released. It's simple, easy to use, and mostly bug-free. May I never miss the bus again.

I can safely add NSTimer to the list of classes with bad documentation: the ownership model is essentially undocumented, and I spent several hours tracking down a crasher that turned out to be timer-related. Timers retain themselves while they're active, but something else (the runloop?) retains them as well. When you invalidate a timer or it expires, the retain count is 1, but if you try to release it, a bit later your program goes kaboom. The timer is autoreleased, so the best way to establish ownership is to retain it when you create and schedule it (retain count: 3), then perform an invalidate (has no effect if timer is already invalid) and release when you're done, relying on the later autorelease to perform a dealloc.

Comments are closed.