Why ARC is not deallocating memory after popViewController

前端 未结 9 776
刺人心
刺人心 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:46

    Try to avoid using strong properties for IBOutlets.

    0 讨论(0)
  • 2021-02-01 02:49

    I would like to say, that my last few days were spent on searching the web for my app memory problem. I was switching between 2 UIViewControllers. One of them had a scroll view which kept all subviews on it. It turned out that that UIVC loads a new scroll view without releasing the previous one. It took me several hours to realize it.

    What I did was:

    Looking for any kind of deadlocks inside the app, then searching for every variable that had a strong atributte and other desperate measures. But what really worked was:

     @IBAction func backBB(sender: UIBarButtonItem) {
        collectionView.removeFromSuperview()
        self.frontView.removeFromSuperview()
        eventsPhotos.removeAll(keepCapacity: false)
        symbolContainerView.removeFromSuperview()
        self.myScrollView.removeFromSuperview()
        dismissViewControllerAnimated(true, completion: {})
    }
    

    I manually removed some views and contents. I've done it in "Back" button but you can do this in other methods like viewWillDisappear(animated: Bool).

    Once I made this, my allocation chart in the developer instruments showed the memory allocation going up and down... And it was solved...

    0 讨论(0)
  • 2021-02-01 02:52

    Nil the popover on dismiss.

    [menuPopup_ dismissPopoverAnimated:YES];
    menuPopup_ = nil;
    
    0 讨论(0)
提交回复
热议问题