Skip navigation.
 
mlRe: Cache Class review (low priority)
FROM : Gregory Weston
DATE : Fri May 02 13:37:27 2008

Jens Alfke wrote:

> On 1 May '08, at 4:49 PM, Western Botanicals wrote:
>

>> [NSTimer scheduledTimerWithTimeInterval: defaultSleepTime target:
>> self selector: @selector(run:) userInfo: nil repeats: YES];

>
> That timer is autoreleased, so you have to retain it or it'll go away
> after your init method returns.


Not unless the docs are lying (and based on heavy timer usage in some 
of my apps, I'm going to claim they're not). From the NSTimer overview:

"Note in particular that run loops retain their timers, so you can 
release a timer after you have added it to a run loop."

That said, proper conformance to the memory contract would be that 
you *do* retain it if you do this...

> Typically you'd then assign it to an ivar; then when you need to 
> stop the
> timer, you call -invalidate and -release on it.


But as long as the OP has no intention of manually invalidating the 
timer, what's already there is sufficient.

Related mailsAuthorDate
mlCache Class review (low priority) Western Botanicals Apr 30, 15:50
mlRe: Cache Class review (low priority) Jean-Daniel Dupas Apr 30, 16:44
mlRe: Cache Class review (low priority) Jens Alfke Apr 30, 17:08
mlRe: Cache Class review (low priority) Western Botanicals May 1, 00:14
mlRe: Cache Class review (low priority) Jens Alfke May 1, 04:30
mlRe: Cache Class review (low priority) Western Botanicals May 2, 01:49
mlRe: Cache Class review (low priority) Jens Alfke May 2, 06:58
mlRe: Cache Class review (low priority) Gregory Weston May 2, 13:37
mlRe: Cache Class review (low priority) Jens Alfke May 2, 17:22
mlRe: Cache Class review (low priority) Western Botanicals May 2, 18:32
mlRe: Cache Class review (low priority) Jens Alfke May 2, 20:03
mlRe: Cache Class review (low priority) Uli Kusterer May 2, 22:29
mlRe: Cache Class review (low priority) Chris Hanson May 3, 04:24