Pop controller in iOS but not destroyed

Source: Internet
Author: User

It was a sad story to work overtime in Saturday. Today when the bug was found a problem, my controller registered a number of monitoring methods. When I pop out of this controller, it seems to be removed from the stack, but when the broadcast, still respond to the monitoring method, it is very embarrassing. So I followed the code and found that I didn't go to the Deinit method (Swift), or the Dealloc method in OC, after pop. Well, today I'll summarize how to find a problem when it comes to this situation, or how to avoid these problems when we write code.

In the final analysis, this occurs when the current controller is strongly referenced by an object, count is not reduced to 0 when the controller POPs, the reference counter is not 0 The system will not release this part of memory for you.

I summed up one, the controller was not destroyed nothing but the following three cases:

Improper use of 1.block blocks. Because Blocak will automatically retain the variables in the method. So, we first check the following Blocak code in your own controller. Do not say exactly how to write, weak.

2. The timer Nstimer is not destroyed, remember to use the controller before the viewwilldisappear to destroy the timer.

3. Agents in the controller must use weak references, do not use strong references. (This should be the least of the situation, I believe that when we first learned the iOS agent this piece, has been told "to write, do not care why", so basically everyone is written weak)

Well, this is the problem that I met at work today, to share with you, if there are other ideas, please leave a message below.

Pop controller in iOS but not destroyed

Related Article

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.