Click the button on page 1 to jump to page 2. At this time, the memory increases by 5 MB. Then click the button on page 2 to dismiss page 2. At this time, the dealloc method of page 2 is executed, but the 5 MB memory is not freed. Why?
Isn’t the memory under ARC released in time?
How should we determine whether a view controller or object is truly released?
Note: I check the memory usage through the debug session of Xcode.
Add the following code to the class and judge the release status of this class by looking at whether there is a log of the class when it is dismissed:
For example, the class name
MyViewController
, if the release is successful, there will be a log ofdealloc MyViewController
.Then debug again to find out what is causing it.
Possible situation:
somewhere
strong
has a reference to this classUse
self
directly inblock
(you should use__weak typeof(self) weakSelf = self
, and then useweakSelf
in block)The controller rewrites the
-(void)dealloc
method. Check whether this method is called when the controller dismisses or pops.Use analyze to analyze App memory
If you are using xcode version 8.0 or above, you can view the memory map.