使用storyboard segues + dismissViewControllerAnimated

时间:2015-09-04 08:54:12

标签: ios swift uiviewcontroller storyboard segue

我尝试使用更复杂的应用程序调试此内存问题,但由于问题也发生在最小的测试应用程序中,我想这意味着它是关于基本结构的事情并非如此。按预期工作(或至少按我们预期的那样)。

以下是设置:

enter image description here

故事板上有三个与segue连接的视图控制器。 MainViewController中的按钮触发segues," close" ImageViewController中的按钮通过dismissViewControllerAnimated关闭它们。 (请注意,我只是使用大图像作为示例 - 重要的是显示这些视图控制器将占用一些非常重要的内存量。)

这里是所有三个代码:

MainViewController:

 class MainViewController: UIViewController {

        @IBAction func openFirstImage(sender: UIButton) {
            self.performSegueWithIdentifier("firstImageSegue", sender: sender)
        }

        @IBAction func openSecondImage(sender: UIButton) {
            self.performSegueWithIdentifier("secondImageSegue", sender: sender)
        }
    }

FirstImageVC:

class FirstImageVC: UIViewController {
    @IBAction func close(sender: UIButton) {
        self.dismissViewControllerAnimated(true, completion: nil)
    }
}

SecondImageVC:

class SecondImageVC: UIViewController {
    @IBAction func close(sender: UIButton) {
        self.dismissViewControllerAnimated(true, completion: nil)
    }
}

运行应用程序,这些是以下事件的分配 - 启动应用程序,打开第一张图片,关闭第一张图片,打开第二张图片,关闭第二张图片:

enter image description here

他们似乎不断加起来,但从未被释放。

现在,每当我弹回MainViewController时,我想要一个" clean"记忆了。所以问题有两个方面:

  • 为什么此设置不会以这种方式工作 - 谁在解雇后保留对视图控制器的引用?
  • 并且有办法解决问题"这种行为?(理想情况下,不会检修整个项目的导航结构)。

0 个答案:

没有答案