[英]Segue to new view controller within a nav bar, the memory keeps rising
I am learning and working on an ios app.我正在学习和开发 ios 应用程序。 I have a nav bar with buttons that are programmed to present other view controllers in the app.
我有一个带有按钮的导航栏,这些按钮被编程为在应用程序中显示其他视图控制器。 Heres a sample of the code:
下面是代码示例:
let vc = storyboard?.instantiateViewController(identifier: “ViewController”) as! ViewController
vc.modalPresentationStyle = .fullScreen
self.present(vc, animated: true, completion: nil)
As I navigate around the app while running the simulation the Memory keeps rising.当我在运行模拟时浏览应用程序时,Memory 不断上升。 Should I be clearing previous pages viewed so that the memory doesn't rise?
我是否应该清除以前查看的页面以使 memory 不会上升?
Every time when presenting a new scene in your app, you as a developer are responsible for presenting and dismissing the scene properly.每次在您的应用程序中呈现新场景时,您作为开发人员都有责任正确呈现和关闭场景。
There are many ways of presenting a scene.呈现场景的方式有很多种。
For example,The push
-style navigation automatically contains/adds controls for backward navigation
because it adds all ViewControllers to its navigation stack
;例如,
push
式导航自动包含/添加用于backward navigation
的控件,因为它将所有 ViewControllers 添加到其navigation stack
中; all ViewControllers will be embedded in the same NavigationController
;所有 ViewController 都将嵌入同一个
NavigationController
中; thus, when dismissing it, you have to write:因此,当解雇它时,你必须写:
navigationController.popViewController(animated: true)
The VC will be popped (removing an element from the top of the stack, newest element in the stack) and not just dismissed. VC 将被弹出(从堆栈顶部删除一个元素,堆栈中的最新元素),而不仅仅是关闭。
In case of presenting scenes modally , these ViewControllers have to have their own NavigationController
.在以模态方式呈现场景的情况下,这些 ViewController 必须有自己的
NavigationController
。 thus, when dismissing it, you have to write:因此,当解雇它时,你必须写:
dismiss(animated: true, completion: nil)
Do you see the difference?你看得到差别吗? If dismissing is handled properly, then there should be no memory leak.
如果解雇处理得当,那么应该没有 memory 泄漏。 Presenting and dismissing is related to Navigation in your app, and every scene has this navigation "section" where you handle dismissing which prevents from memory leak.
呈现和关闭与应用程序中的导航有关,每个场景都有这个导航“部分”,您可以在其中处理关闭,以防止 memory 泄漏。
Hope it can help you a little bit.希望它可以帮助你一点点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.