Man of One Way
Man of One Way

Reputation: 3980

NSTimer invalidation

If I create a timer which never repeats

[NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(updateSystems) userInfo:nil repeats:NO];

do I still need to invalidate it?

Also, is releasing the instance one step in the invalidate method? Since I'm not using alloc my timer variable shouldn't have to be released, although when creating a timer it automatically should create a new thread? Does the timer still add up on the stack? I need some clarity.

Thank you

Upvotes: 1

Views: 541

Answers (2)

Cyprian
Cyprian

Reputation: 9453

You are not creating any pointer to NSTimer. You are using it directly through a class method. This method does not creates a new instance of NSTimer so you don't have to release it.

Upvotes: 1

JeremyP
JeremyP

Reputation: 86691

See the documentation for the method. It says:

repeats
If YES, the timer will repeatedly reschedule itself until invalidated. If NO, the timer will be invalidated after it fires.

Upvotes: 3

Related Questions