Any memory leak (or over-instantiation of objects) when using iOS Storyboard Seque “Model” or “Push” style?

萝らか妹 提交于 2019-12-10 10:07:21

问题


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"?


回答1:


@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).




回答2:


Yes it will keep stacking them up either way.

Just to clarify though, it wont cause any leaks.



来源:https://stackoverflow.com/questions/10584601/any-memory-leak-or-over-instantiation-of-objects-when-using-ios-storyboard-seq

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!