KVOを使用してコンテキストオブジェクトによってプロパティが監視される、直接のNSObjectサブクラスであるモデルオブジェクトがあります。
次のように、モデル オブジェクトの dealloc で KVO から登録を解除しています。
- (void) dealloc
{
[self.context unregisterObject:self];
}
コンテキストのメソッドは次のようになります。
- (void) unregisterObject:(MyCustomObject*) inObject
{
for (NSString *property in [inObject propertyNamesToObserve])
{
[inObject removeObserver:self forKeyPath:property context:(void*)kCustomContext];
}
}
以下に投稿されているように、まだランタイムからメッセージを受け取っているので、-dealloc が遅すぎて KVO から登録を解除できないのではないかと考えています。
An instance 0x10045fc10 of class MyCustomObject was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger. Here's the current observation info:
この投稿によると、私がやっていることは問題ないはずです: KVO and ARC how to removeObserver
それとも私は何かを見落としていますか?dealloc が呼び出されたときに、コンテキストが非 nil であることを確認しました。