ブロック内で使用されているオブジェクトが解放されないという問題に対処していました。
最初に私はこのコードを持っていました:
__block SOMABannerView* bannerView=_bannerView;
self.viewWillDissappearObserver = [center addObserverForName:UIViewWillDissappearNotification object:self.delegate.viewControllerForPresentingModalView queue:mainQueue usingBlock:
^(NSNotification *note) {
[bannerView setAutoReloadEnabled:NO];
}];
オブジェクトをコピーして保持しないと思われるため、__block を使用しましたが、Instruments でこのコードを分析していたときに、クラス SOMABannerView のオブジェクトが割り当て解除されていないことに気付いたので、次のように変更しました。
self.viewWillDissappearObserver = [center addObserverForName:UIViewWillDissappearNotification object:self.delegate.viewControllerForPresentingModalView queue:mainQueue usingBlock:
^(NSNotification *note) {
[_bannerView setAutoReloadEnabled:NO];
}];
どちらも機能しなかったので、ブロックを回避するために NSNotificationCenter の別のメソッドを使用することになりましたが、それでも __block がオブジェクトを保持していた理由がわかりません。誰かがこれを明確にしてくれますか? __block の概念が間違っていますか?