Is there any reason to keep the planned NSTimer if you don't need to cancel it?

I go back to some cool code to tidy it up, and I see that I keep NSTimers being returned from scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:and keeping them in the field, and then freeing and nullifying the field when it starts. In some cases, I use a timer to send him an invalid message later, but in many cases not.

In later code, I usually just schedule a timer and forget about it. I understand that the constructor method is auto-implemented, and the timer is stored in the startup loop while it is active, so I do not see any problems with this.

So, just to finish my understanding - is there any other reason I should hold on to my timers, or what am I doing now on the accepted idiom?

This is all in the context of iPhone code, but I don’t think it is an iPhone.

+3
source share
2 answers

I just let the start cycle handle the save, myself is the start cycle to which the timer belongs, and not to me. If you understand what I mean.

+3
source

I answer my question.

Basically I asked a question because I was looking through class reference documents, and this problem was not clearly explained. Since then I read the sections "Programming a timer": using the article "Timers" in the ADC, and it covers it very well, especially the memory management section at the end.

, ( , invalidate, isValid ..) .

+1

Source: https://habr.com/ru/post/1704077/


All Articles