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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -