Bra*_*'in 5 xcode memory-management ios swift
我有一个使用注册/连接过程快速编程的 XCode 项目。连接后,即使应用程序重新启动,您也不会重复此过程,直到单击“注销”按钮。
我注意到,如果您在启动应用程序时遵循注册/连接过程,则内存约为 500Mb,而如果应用程序以连接的用户启动,则内存约为 140Mb。
注册过程由 3 个与自定义 Segue 连接的视图控制器组成。通过以下代码访问登录视图:
func switchRootViewController(rootViewController: UIViewController, animated: Bool, completion: (() -> Void)?)
{
if animated
{
UIView.transitionWithView(window!, duration: 0.5, options: .TransitionCrossDissolve, animations:
{
let oldState: Bool = UIView.areAnimationsEnabled()
UIView.setAnimationsEnabled(false)
self.window!.rootViewController = rootViewController
UIView.setAnimationsEnabled(oldState)
}, completion: { (finished: Bool) -> () in
if (completion != nil)
{
completion!()
}
})
}
else
{
window!.rootViewController = rootViewController
}
}
Run Code Online (Sandbox Code Playgroud)
其中 rootViewController 被我要加载的登录视图替换,如下所示:
func goToNextView()
{
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let homeViewController = storyboard.instantiateViewControllerWithIdentifier("conversationViewController") as!ConversationViewController
homeViewController.currentUser = self.currentUser
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.switchRootViewController(home, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
但是它不会清理内存。
这是内存分配的屏幕:
所以我的问题是:是否可以“杀死”某些视图控制器以清理内存?
例如,当您连接时,很明显“杀死”注册过程视图。
谢谢您的回答。