iOS development advanced face Test-arc the role of Dealloc

Source: Internet
Author: User
Tags notification center

In the MRC era, we need to do a lot of things in dealloc, such as releasing objects, etc.

Now we have entered the arc era, for the release of ordinary objects, the system has helped us do;

Is there any peace of mind? What are we supposed to do under arc?


View:

ARC, the system can help us to release the object, and its contained objects;

However, it is not possible to release something that does not belong to that object, such as:


1. Notice of the viewer


Since the notification center is a single instance of the system, you are actually registered with the Notification center when you register the observer for the notification.

At this point, even if the arc under the system helps us release the object, but the observation in the Notification center is still not removed, then when there is

The notification will still attempt to invoke the method that accepts the notification for that object, which may cause some problems.

It's a bit like, you're off six o'clock at night ... But without a swipe ...


2. Cancellation of a strong delegate/reference to a static object (e.g. Xmppmannerger delegatequeue)


For other objects to treat you as a delegate delegate, and as a strong reference, you are released on your own, but the reference to your object is still there,

You will need to remove the delegate when referencing your object.


3. Do some other things


An object, such as a viewcontroller, may need to deal with the server before it is destroyed;

Then we can also write in the Dealloc


For the underlying implementation of Dealloc, you can refer to the OBJC Runtime code


Examples of what we should do under arc:

-(void) dealloc{    [[nsnotificationcenter defaultcenter] removeobserver:self];//Remove Notification viewer    [[Xmppmanager Sharedmanager] removefromdelegatequeue:self];//Remove delegate reference  [[MyClass shareinstance]  dosomething]//other Actions   }


We don't need to do it under arc.


-(void) dealloc{    _name = nil;   [_time invalid];}


Summary: The role of Dealloc under ARC is to release resources that the system cannot release, or references to other objects that the object uses.


Source: http://blog.csdn.net/yangbingbinga/







iOS development advanced face Test-arc the role of Dealloc

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.