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