是调用performSelector的对象:withObject:afterDelay由NSRunLoop保留? [英] Is object that calls performSelector:withObject:afterDelay get retained by the NSRunLoop?
问题描述
我有一个特定的对象,每X秒执行一次刷新。 (更新程序)
我这样做重复更新的方式是通过调用 performSelector:withObject:afterDelay
,在我的选择器中我重新调度
I have a certain object that perform a "Refresh" every X seconds. ("The Updater")
The way I'm doing this repetitive update is by calling performSelector:withObject:afterDelay
and in my selector I'm re-scheduling as necessary.
当然,我有一个方法通过调用 cancelPreviousPerformRequests
来停止这些调用。
Of course I have a method to stop these invokations by calling cancelPreviousPerformRequests
.
问题是这个Updater永远不会被释放。
只有一个其他对象保留更新程序(AFAIK),保留对象 被释放,并调用 [self setUpdater:nil];
The problem is that this "Updater" is never being deallocated.
There is only one other object that retaining the Updater (AFAIK), and the retaining object is being deallocated and calls [self setUpdater:nil];
我怀疑这与 performSelector有关:withObject:afterDelay
方法,但我在文档中找不到对该问题的任何引用。
I'm suspecting that this is have something to do with the performSelector:withObject:afterDelay
method, but I couldn't find any reference to that question in the documentation.
任何人都可以确认或关闭它?
Can anyone confirm or dismiss it?
感谢!
附录
这是调度方式:
APPENDIX This are the scheduling methods:
-(void) scheduleProgressUpdate
{
[self stopProgressUpdates]; // To prevent double scheduling
[self performSelector:@selector(updateProgress)
withObject:nil
afterDelay:1.0];
}
-(void) updateProgress
{
// Perform update..
[self scheduleProgressUpdate];
}
-(void) stopProgressUpdates
{
[NSObject cancelPreviousPerformRequestsWithTarget:self
selector:@selector(updateProgress)
object:nil];
}
推荐答案
据我所知performSelector方法保留其接收者和参数。
As far as I know the performSelector method retain its receiver and arguments.
这篇关于是调用performSelector的对象:withObject:afterDelay由NSRunLoop保留?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!