Re: Invalidate non-repeating NSTimer after fired?
Re: Invalidate non-repeating NSTimer after fired?
- Subject: Re: Invalidate non-repeating NSTimer after fired?
- From: Lee Ann Rucker <email@hidden>
- Date: Fri, 03 Aug 2012 14:17:49 -0700
Not if you've retained the timer - and if you haven't, then you shouldn't release it. Conversely if you *have*, you should release and nil it when it fires.
On Aug 3, 2012, at 2:10 PM, Charlie Dickman wrote:
> You must use the 2nd way. If you don't you could get a memory exception if the timer has fired and, therefore, been invalidated.
>
> On Aug 3, 2012, at 4:19 PM, Trygve Inda wrote:
>
>> NSTimer* myTimer = [NSTimer scheduledTimerWithTimeInterval:60 target:self
>> selector:@selector(wantsUpdate:) userInfo:nil repeats:NO]
>>
>> Sometime after it fires (and occasionally before), I call
>>
>> if ( myTimer )
>> {
>> [myTimer invalidate];
>> [myTimer release];
>> myTimer = nil;
>> }
>>
>>
>> Should I really be doing:
>>
>> if ( myTimer )
>> {
>> if ([myTimer isValid])
>> [myTimer invalidate];
>>
>> [myTimer release];
>> myTimer = nil;
>> }
>>
>>
>>
>> I am doing it the first way without trouble... At least I think it is ok.
>> The docs say non-repeating timers are invalidated after they fire.
>>
>> Which way is better?
>>
>> Comments?
>>
>>
>>
>>
>> _______________________________________________
>>
>> Cocoa-dev mailing list (email@hidden)
>>
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>
>> Help/Unsubscribe/Update your Subscription:
>>
>> This email sent to email@hidden
>
> Charlie Dickman
> email@hidden
>
>
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden