Is object that calls performSelector:withObject:afterDelay get retained by the NSRunLoop?

亡梦爱人 提交于 2019-12-11 01:06:11

问题


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.

Of course I have a method to stop these invokations by calling cancelPreviousPerformRequests.

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];

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?

Thanks!

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];
}

回答1:


As far as I know the performSelector method retain its receiver and arguments.



来源:https://stackoverflow.com/questions/10928118/is-object-that-calls-performselectorwithobjectafterdelay-get-retained-by-the-n

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!