ope*_*rog 13 objective-c grand-central-dispatch ios automatic-ref-counting
(但这个问题完全不同)
这个非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);
}
Run Code Online (Sandbox Code Playgroud)
我了解到您不必在ARC下发布队列对象.但其他GCD对象如调度源?
不,前提是你的部署目标是iOS 6.0以上的Mac OS X 10.8或更高版本,如解释在这里.
所有GCD对象都由ARC管理,因此您无需显式管理其内存.什么是真的dispatch_queue_t也适用于所有其他GCD对象.
这被记录在<os/object.h>正确的定义之上OS_OBJECT_HAVE_OBJC_SUPPORT.
默认情况下,在使用Objective-C编译器构建时,将诸如GCD和XPC对象的libSystem对象声明为Objective-C类型.这允许他们参与ARC,通过Blocks运行时进行RR管理,并通过静态分析器进行泄漏检查,并使它们能够添加到Cocoa集合中.
您也可以使用-DOS_OBJECT_USE_OBJC=0编译器标志选择退出此行为.
| 归档时间: |
|
| 查看次数: |
6849 次 |
| 最近记录: |