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.
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 mails | Author | Date |
|---|---|---|
| Western Botanicals | Apr 30, 15:50 | |
| Jean-Daniel Dupas | Apr 30, 16:44 | |
| Jens Alfke | Apr 30, 17:08 | |
| Western Botanicals | May 1, 00:14 | |
| Jens Alfke | May 1, 04:30 | |
| Western Botanicals | May 2, 01:49 | |
| Jens Alfke | May 2, 06:58 | |
| Gregory Weston | May 2, 13:37 | |
| Jens Alfke | May 2, 17:22 | |
| Western Botanicals | May 2, 18:32 | |
| Jens Alfke | May 2, 20:03 | |
| Uli Kusterer | May 2, 22:29 | |
| Chris Hanson | May 3, 04:24 |






Cocoa mail archive

