クラス(非ARC環境)があるとします:
@interface SomeObject : NSObject {
UILabel *someLabel;
dispatch_queue_t queue;
}
- (void)doAsyncStuff;
- (void)doAnimation;
@end
@implementation SomeObject
- (id)init {
self = [super init];
if (self) {
someLabel = [[UILabel alloc] init];
someLabel.text = @"Just inited";
queue = dispatch_queue_create("com.me.myqueue", DISPATCH_QUEUE_SERIAL);
}
return self;
}
- (void)doAsyncStuff {
dispatch_async(queue, ^{
...
// Do some stuff on the current thread, might take a while
...
dispatch_async(dispatch_get_main_queue(), ^{
someLabel.text = [text stringByAppendingString:@" in block"];
[self doAnimation];
}
}
}
- (void)doAnimation {
...
// Does some animation in the UI
...
}
- (void)dealloc {
if (queue) {
dispatch_release(queue);
}
[someLabel release];
[super dealloc];
}
私のブロックが開始され、このオブジェクトのインスタンスへの参照を保持している他のすべてがそれを解放した場合、ネストされたブロックがインスタンス変数 (および自己) を参照するため、dealloc が呼び出されないことが保証されますか? その deallocネストされたブロックが終了した後に発生しますか? 私の理解では、私のブロックには自己への強い参照があるため、これはコーシャでなければなりません.