这是我的问题:
我有一个模型类,其中有一个NSTimer我希望Timer在模型对象的整个生命周期内运行.初始化很简单:我在init方法中只有以下代码行:
self.maintainConnectionTimer =
[NSTimer scheduledTimerWithTimeInterval:1
target:self
selector:@selector(maintainConnection)
userInfo:nil
repeats:YES];
Run Code Online (Sandbox Code Playgroud)
但是,我的问题是,当模型从内存中释放时,如何使此计时器无效? 现在,这通常很容易,但据我所知,当您安排NSTimer操作系统维护一个指向Timer对象的强指针时.
我应该怎么处理这个?是否有一种方法在模型从内存中释放之前被调用?