ios - Could someone clarify this block for me? -
i dealing problem in object used inside block wouldn't release.
first had code:
__block somabannerview* bannerview=_bannerview; self.viewwilldissappearobserver = [center addobserverforname:uiviewwilldissappearnotification object:self.delegate.viewcontrollerforpresentingmodalview queue:mainqueue usingblock: ^(nsnotification *note) { [bannerview setautoreloadenabled:no]; }];
i used __block because supposedly wouldn't copy , retain object , when analyzing code instruments noticed objects class somabannerview weren't being deallocated, changed to:
self.viewwilldissappearobserver = [center addobserverforname:uiviewwilldissappearnotification object:self.delegate.viewcontrollerforpresentingmodalview queue:mainqueue usingblock: ^(nsnotification *note) { [_bannerview setautoreloadenabled:no]; }];
which didn't work either, ended using method nsnotificationcenter avoid block, still don't why __block retaining object, clarify me? have wrong concept of __block?
it won't retain object in non-arc environment, will in arc environment. arc, use __weak
instead of __block
.
source: http://clang.llvm.org/docs/automaticreferencecounting.html#blocks
Comments
Post a Comment