【发布时间】:2012-12-16 16:24:33
【问题描述】:
我有一些 typedef:
typedef void (^myBlock)(SomeObject);
我有一些对象
@interface SomeObject : NSObject
@end
// Method of some arbitrary class
- (void) someMethod1 {
SomeObject *someObject = [[SomeObject alloc] init];
myBlock block = ^(SomeObject obj){
// When _block(someObject)_ will be called inside someQueue -
// Is it guaranteed that someObject will be alive, retained inside me?
// Do something complex and involving (or not) obj ...
}
dispatch_async(someQueue, ^{
// Some bunch of code - after which we are sure that
// by the next line someMethod1 will run out, so its scope is lost
block(someObject);
});
}
问题放在 block 变量的块中:是否保证我们传递给 someQueue 队列中的块 block 的 someObject 对象会在 block 块内活着并保留?
这个问题是我刚刚提出的问题的一个更复杂的变体:Does a passing of an object to a block guarantee that its lifecycle will be retained?。
【问题讨论】:
-
我想你可以在我的回答中问。
-
谢谢@RamyAlZuhouri!没有更多类似的问题。
标签: objective-c automatic-ref-counting objective-c-blocks