NSTimer Memory Management Issues

By default, the returnd object using the allocor method copyis retain countequal to 1, so you must let it go yourself.

But through the NSTimer sample codes

// in one method start the timer (which myTimer is an Class Instance)
myTimer = [NSTimer scheduledTimerWithTimeInterval: 1
                   target: self selector: @selector (method :)
                   userInfo: nil repeats: YES];

// in another method 
[myTimer invalidate];
myTimer = nil;

My question is why [NSTimer sche **] returns an object that you do not need to save, but you can access it anywhere. And you do not need to release it, but only call invalidateon it.

+3
source share
1

, . , . , , .

NSTimer docs:

. , , - . NSRunLoop Threading . , , .

:

scheduledTimerWithTimeInterval: : : scheduledTimerWithTimeInterval: : : UserInfo: : .

, , , .

+4

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


All Articles