I'm using ARC and I'm calling [[NSNotificationCenter defaultCenter] removeObserver:someObserver];
in observer's dealloc
.
From NSNotificationCenter Class Reference
Be sure to invoke this method (or removeObserver:name:object:) before notificationObserver or any object specified in addObserver:selector:name:object: is deallocated.
NSNotificationCenter does not retain the observer.
Q1: Is NSNotificationCenter
thread-safe?
In case, the observer is being deallocated(and removing observer from the notification center) and another thread post a notification at the same time.
I encounter random crash and I suspect this is the case.
Q2: Is this situation possible?
Q3: Does it lead to EXC_BAD_ACCESS
?
Q4: Then, is it safe to call [[NSNotificationCenter defaultCenter] removeObserver:someObserver];
in observer's dealloc
?
Q5: If it is not safe, where should I call removeObserver:
?