Why does ios leave dealloc or cause Memory Leak in UIViewController,
Since MyLeaksFinder is imported into the project, Memory Leak prompts are often reported in the project. After several debugging times, several possible causes of this situation are summarized:
1. The NSTimer timer is used in the VC. After the VC pushes -- pop, if the NSTimer object is not destroyed, the memory leakage will occur, that is, the current VC is referenced, as a result, the reference count of the controller is increased by 1. If the nstloc is not destroyed, the Controller keeps the VC and cannot be released. Therefore, the dealloc method is not called. Therefore, you need to destroy the NSTimer used by the Controller before viewWillDisappear.
Destruction method: [timer invalidate]; // destroy timer
Timer = nil; // set nil
Or the destroy method in GCD:
Dispatch_source_cancel (_ timer );
2. Strong reference self is used in the Block code Block, which is easily caused by loop reference and the object cannot be released for a long time.
You can:
# Define WS (weakSelf )? _ Weak _ typeof (self) weakSelf = self;
Use Weak reference weakSelf to replace self,
Or when the project calls internal member variables and attributes in the callback code block, self. name or _ name will cause circular reference. The method is the same as above.
3. the proxy method attribute used in the project VC is not the weak attribute. The specific method is as follows:
: @ Property (nonatomic, weak) id delegate;
The specific causes are still being explored. If there are any new causes, you are welcome to add them in the comment area. I wish you a bright future!