IOS development Advanced Interview Questions-Role of dealloc under ARC,-arcdealloc
In the MRC era, we need to do a lot in dealloc, such as releasing objects;
Now we have entered the ARC era. The system has helped us with the release of common objects;
Can I rest assured? What should we do under ARC?
Opinion:
Under ARC, the system can help us release this object and its contained objects;
However, some things that do not belong to this object cannot be released, such:
1. Notification observer
Because the notification center is a single example of the system, when you register the notification observer, you actually register in the notification center,
At this time, even if the system under the ARC helped us release the object, but the observation in the notification center is still not removed, when there is
This notification still calls the method for receiving the notification from this object, which may cause some problems.
This is a bit like, you get off work at six o'clock, but you didn't swipe your card ...,
2. Release of strong Commission/reference of static objects (for example, XMPPMannerger's delegateQueue)
When you use other objects as delegate and are strongly referenced, you are immediately released, but your object is still being referenced,
In this case, you need to remove the delegate When referencing your object.
3. Perform other operations
An object, such as a ViewController, may need to deal with the server before it is destroyed;
In this case, we can also write in dealloc
For the underlying implementation of dealloc, refer to the objc runtime code.
For example, what we should do in ARC:
-(Void) dealloc {[[nsicationcenter center defaultCenter] removeObserver: self]; // remove notification observer [[XMPPManager sharedManager] removeFromDelegateQueue: self]; // remove the delegate reference [[MyClass using instance] doSomething] // other operations}
We don't have to do anything under ARC.
- (void)dealloc{ _name = nil; [_time invalid];}
Conclusion: The Role of dealloc in ARC is to release resources occupied by this object that cannot be released by the system, or reference other objects to this object.
From: http://blog.csdn.net/yangbingbinga/