Use of Dealloc in IOS arc environment

Source: Internet
Author: User

As we all know, when developing iOS, using arc, the DEALLOC function does not need to be implemented, but it will go wrong.

But in some special cases, the Dealloc function is still needed.

For example, when the screen is closed, some resources of Viewcontroller need to be released,

In the viewdiddissppear is not necessarily suitable, viewdidunload generally only in memory warning when the call.

Without arc, we would naturally think of the dealloc function.

In fact, in the ARC environment, there is no dealloc function is forbidden, or can be used. Just don't need to call [supper dealloc] anymore.


For example, there is a uiwebview on the screen, its delegate is the viewcontroller of the picture, after the WebView loading is completed, it is necessary to do something, for example, to stop the indicator and so on.

If the screen is closed before webview loading is complete, the Viewcontroller is released after the screen is closed. However, since WebView is loading the page and is not released immediately, after the page is loaded, the callback method in delegate (Viewcontroller) will be faulted because Viewcontroller has been released at this time. (Message sent to deallocated instance)

The solution is to release WebView's delegate in Dealloc.

-(void) Dealloc {

Self.webView.delegate = nil;

}

Use of Dealloc in IOS arc environment

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.