search

Home  >  Q&A  >  body text

objective-c - A problem about memory release under ARC in iOS development

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.

曾经蜡笔没有小新曾经蜡笔没有小新2725 days ago1313

reply all(2)I'll reply

  • 世界只因有你

    世界只因有你2017-07-03 11:45:05

    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)

    reply
    0
  • 巴扎黑

    巴扎黑2017-07-03 11:45:05

    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.

    reply
    0
  • Cancelreply