当使用iOS Storyboard Seque“模型"时,任何内存泄漏(或对象的过度实例化)都将被释放.或“推"风格? [英] Any memory leak (or over-instantiation of objects) when using iOS Storyboard Seque "Model" or "Push" style?

查看:120
本文介绍了当使用iOS Storyboard Seque“模型"时,任何内存泄漏(或对象的过度实例化)都将被释放.或“推"风格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我正在开发一个具有两个屏幕的简单iPhone应用程序:登录和注册屏幕.在登录"屏幕中,它具有注册"按钮,该按钮进入注册"屏幕.同样,在注册"屏幕中,它具有登录"按钮,该按钮转到登录"屏幕.所有操作均使用iOS Storyboard Segue模式"样式实现.

问题是:每当以模式"样式呈现视图控制器时,是否会继续向堆栈中添加新视图?因此,如果我在登录"和注册"屏幕之间反复切换,它是否会每次实例化新对象并不断累积内部数组容器(即堆栈)?

此外,如果我将样式更改为推送",那么类似问题的情况将如何?并非每次按下"按钮时都会一直将新的视图对象添加到顶部吗?

解决方案

@trapper是绝对正确的.您可以将它们堆叠起来,但是只要您用dismissViewControllerAnimated:completion:取消模态"或用popViewControllerAnimated:弹出推送的视图控制器,它就不会泄漏.如果您错误地从登录/注册屏幕回到主视图,则该内存将不会被释放(从技术上讲这不是泄漏,但这是错误的,您也不会释放该内存).

Let's say I'm developing a simple iPhone app with two screens: Login and Register screens. Within the Login screen, it has the "Register" button which takes to the Register screen. Likewise, within the Register screen, it has the "Login" button which takes to the Login screen. All is implemented using iOS Storyboard Segue "Modal" style.

The question is: does keep adding a new view to a stack everytime a view controller is presented by a segue "Modal" style? So, if I repeatly switch between the Login and Register screens, will it instantiates new objects everytime and keeps accumulating with an internal array container (ie. stack)?

Further, if I change the style to "push", how will the situation be like to the similar question? Doesn't "push" keeps adding new view objects to the top everytime it is "pushed"?

解决方案

@trapper is absolutely correct. You segues will stack them up, but it won't leak as long as you dismiss your "modal" with dismissViewControllerAnimated:completion: or pop your pushed view controller with popViewControllerAnimated:. If you erroneously have a segue from your login/register screen back to the main view, then that memory won't be released (which isn't technically a leak, but it's wrong and you won't release the memory).

这篇关于当使用iOS Storyboard Seque“模型"时,任何内存泄漏(或对象的过度实例化)都将被释放.或“推"风格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆