objective-c - A problem about memory release under ARC in iOS development
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-07-03 11:43:05
0
2
1304

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.

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(2)
世界只因有你

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:

#pragma mark - dealloc

-(void)dealloc {
    NSLog(@"dealloc %@", NSStringFromClass([self class]));
}

For example, the class name MyViewController, if the release is successful, there will be a log of dealloc MyViewController.
Then debug again to find out what is causing it.

Possible situation:

  • somewhere strong has a reference to this class

  • Use self directly in block (you should use __weak typeof(self) weakSelf = self, and then use weakSelf in block)

巴扎黑
  1. The controller rewrites the -(void)dealloc method. Check whether this method is called when the controller dismisses or pops.

  2. Use analyze to analyze App memory

  3. If you are using xcode version 8.0 or above, you can view the memory map.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template