jacobronniegeorge
jacobronniegeorge

Reputation: 555

Storyboard+Modal Segue + Memory

I have a storyboard with 6 View Controllers and their respective views. I do NOT have any navigation controllers associated with these 6 View Controllers.

To go from one view controller to another, the swipe gesture recognizer is used alongside a modal segue. All view controllers have alteast 1, and sometimes even two swipe gesture based modal segues to other view controllers.

My question is, do I need to worry about memory? When I swipe are these viewcontrollers going to be infinitely added to memory eventually causing the app to crash?

An example could be: Say I am in the first VC and I swipe Right to the second VC, then swipe once again to Right to Third VC, then swipe left twice to get back to the First VC will the memory contain this:

Memory: First VC, Second VC, Third VC, Another Copy of Second VC, Another copy of First VC?

I know it seems like a stupid question but since I have only started programming a couple days ago I am very worried I will be having memory issues.

I would appreciate your thoughts and any potentially helpful links to places that dicusses this issue.

Upvotes: 2

Views: 1031

Answers (2)

CocoaEv
CocoaEv

Reputation: 2984

you have a good question and it depends on how you are creating and dismissing your view controllers. Normally a design like you mentioned would be built using a built in controller like UINavigationController or UIPageViewController or maybe using a scrollview.

If you are "presenting" new view controllers, then you need to dismiss to remove them. If your not dismissing, then you view controllers will stick around.

If you are using segue's, remember that each segue creates a new instance.

If your logic generally says - swipe right: new modal segue, swipe left: dismiss, then you will be cleaning up as you go. This works if its ok that each right swipe creates a new instance.

If you need the six view controllers to stay in memory all the time, you may want to look at using a pageViewController or roll you own solution. I have seen some nice solutions like you describe using a scroll view.

If you wanted to use a scroll view, basically you would crete an array, load the array with the six instances of your view controllers, then load the scroll view for horizontal scrolling. Add the gesture recognizers and logic for left/right swipes and you have a nice horizontal page scroller.

Here is a very nice reference and tutorial that seems to solve the solution you are describing. http://www.wannabegeek.com/?p=168

good luck and happy new year.

Upvotes: 1

artey
artey

Reputation: 1243

As long as you dont keep strong references to the view (or its subviews, like buttons...), they will be deallocated if needed.

Upvotes: 0

Related Questions