If my instance is observing some property of another object, am I supposed to call removeObserver:forKeyPath: in dealloc?
removeObserver:forKeyPath: in dealloc
Asked Answered
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.
You need to use -removeObserver:forKeyPath: to remove the observer before -[NSObject dealloc] runs, so yes, doing it in the -dealloc method of your class would work.
refer this questions.
Removing an Observer
question2
© 2022 - 2024 — McMap. All rights reserved.