When arc is turned on, does the Nsnotificationcenter removeobserver need to be called and when is it called?
Today in StackOverflow see a question, arc case whether need to call removeobserver, oneself think of, really is a problem, studied a bit.
On the code:
-(void) dealloc { [[nsnotificationcenter Defaultcenter] removeobserver:self];}
Originally thought in the Arc Dealloc Way is already abandoned, but the fact is that it still exists, but not as in the MRC also need to call [super dealloc] , in the ARC environment, this method is not available, otherwise the compiler directly error.
Then I thought the dealloc way would normally be called?
Here's how to add an observer:
[[Nsnotificationcenter defaultcenter] addobserver:self selector: @selector (method:) Name:@ " postkey" object: nil";
The first parameter of this method observer is not retain operation, so it does not form a circular reference, but is it necessary to call Removeobserver?
The answer is of course: it is necessary!
If this object is released, when the post message is called, it will be reported that the object is released error, resulting in a flashback, so in addition to the observer's object, it must be destroyed when it is deleted from the message center!
ios-Nsnotificationcenter Removeobserver need to call after opening arc