Why ARC is not deallocating memory after popViewController

前端 未结 9 772
刺人心
刺人心 2021-02-01 02:20

I\'m pushing and popping ViewControllers in UINavigationController.

I\'m tracking the memory consumption of my app. While pushing the new viewController the memory consu

9条回答
  •  盖世英雄少女心
    2021-02-01 02:35

    Make sure your viewcontroller (A) has no reference of any other viewcontroller (B) or any object it has. Incase it has then make sure that VC-B is not referencing back VC-A. If it has some reference back to VC-A then make it a weak property. Otherwise strong retain cycle will keep the VC in memory even if its popped.

    • Another thing is to check wether theres any closure in your VC, check its body if it is referencing any property or method with self then make a Capture list to avoid retain cycle as "Closures are Reference Types"
    • Check if theres any NSNotification observer you are not releasing

    • Make a print call in deinit method to check wether its deallocated.

    For further understanding on memory management:

    • https://medium.com/mackmobile/avoiding-retain-cycles-in-swift-7b08d50fe3ef
    • https://www.youtube.com/watch?v=GIy-qnGLpHU

提交回复
热议问题