Any memory leak (or over-instantiation of objects)

2019-05-18 05:55发布

问题:

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.