(但这个问题完全不同)
这个非 ARC 代码示例设置了一个基于 GCD 的计时器,并为 dispatch_source_t 对象调用 dispatch_release:
__block BOOL done = NO;
dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_main_queue());
if (timer) {
uint64_t milliseconds = 100ull;
uint64_t interval = milliseconds * NSEC_PER_MSEC;
uint64_t leeway = 10ull * NSEC_PER_MSEC;
__block typeof(self) _self = self;
dispatch_source_set_timer(timer, dispatch_walltime(NULL, 0), interval, leeway);
dispatch_source_set_event_handler(timer, ^{
//[_progressBar setProgress:exportSession.progress animated:YES];
if (done) {
dispatch_source_cancel(timer);
dispatch_release(timer);
_self.exportingMovieLabel.hidden = YES;
_self.exportingProgress.hidden = YES;
}
});
dispatch_resume(timer);
}
我了解到您不必在 ARC 下释放队列对象。但是像调度源这样的其他 GCD 对象呢?