Search code examples
objective-ccocoakey-value-observingdealloc

removeObserver:forKeyPath: in dealloc


If my instance is observing some property of another object, am I supposed to call removeObserver:forKeyPath: in dealloc?


Solution

  • Yes

    ...unless there is a more appropriate time earlier in execution.

    Observers are held as nonretained references. Failing to un-register can result in your deallocated instance being messaged.