I have the following case, there is an event type (data from users), the current user can open this event in more detail. Other users can participate in it and the current user can go to the profile of each user. The user profile contains the events (which it created) and the current user can also go to them. The problem is that if you do this many times (like 15 transitions) then the application consumes 214 megabytes (iPhone 7) already, and if so, then I think the application may fall. There is no memory leak in the application, as I checked with tools and if I click on tab (the root controller is the heir from UITabBarController
), the memory comes to its normal state (almost like when the application is started). I'm interested in how best to implement this system (for example, as it is done on Twitter, there it is possible to switch from one user's newsline to another user's newsline and so on). Thanks for the help.
Asked
Active
Viewed 158 times
0

Alexander Khitev
- 6,417
- 13
- 59
- 115
-
are you performing segues for transition ? and do one thing when ever you transit from one view to another just delicate all the allocated variables like arrays strings anything that is allocated in ViewDidDisappear – iOS Geek Jul 27 '17 at 03:59
-
@iOSGeek No, I'm pushing a new UIViewController with the UINavigationController. – Alexander Khitev Jul 27 '17 at 04:00
-
okay are you using one nav Controller for transitions or multiple nav ? – iOS Geek Jul 27 '17 at 04:03
-
@iOSGeek In each UITabBar there is only one UINavigationController – Alexander Khitev Jul 27 '17 at 04:04
-
I am asking for multiple transitions are you changing just rootViewController or adding a new Nav in stack everytime a transition takes place – iOS Geek Jul 27 '17 at 04:05
-
@iOSGeek I add a new UIViewController to the stack each time – Alexander Khitev Jul 27 '17 at 04:07
-
@iOSGeek I also understand that if you open just empty UIViewController which do not contain content, then all memory will be in normal state, but I have all the controllers have images. – Alexander Khitev Jul 27 '17 at 04:09
-
instead of adding new UiviewController each time just set the new ViewController as your rootViewController it will save memory. – iOS Geek Jul 27 '17 at 04:09
-
Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/150246/discussion-between-ios-geek-and-alexsander). – iOS Geek Jul 27 '17 at 04:09
-
@iOSGeek No, this is not possible, because the user should be able to return to the previous screen. – Alexander Khitev Jul 27 '17 at 04:10
-
The ViewControllers are the same? just the data changes? – Pochi Jul 27 '17 at 07:29
-
@Pochi See, there are only 4 types of Controllers, this is the Profile Screen, two types of Events Controller and Chat Controller. – Alexander Khitev Jul 27 '17 at 07:47
-
Why don't you reuse them then? Just keep a reference to the ID of the data that should be shown, and use 2 controllers of the same type. Then if a new controller has to be shown show the one that is not currently displayed with the new ID and Data, if the user goes back once it will show the previous one, if the user goes down further behind use the saved reference to show a VC. – Pochi Jul 27 '17 at 08:07
-
@Pochi I did not know about this method, that is, you can simply take from the stack viewControllers the type of controller that should display the data and do push? – Alexander Khitev Jul 27 '17 at 08:11
1 Answers
0
I reduced the memory consumption of each new ViewController as much as possible. Do not limit the user in the number of open one after another screens - so does not even Apple (example - Apple Music). If the user goes 500 times on the screens without going back, the application will run out of memory and it will fall, which is normal - if the user wants to break, then it will succeed. You can, however, minimize the chance of falling from a lack of memory if you release unused resources in invisible ViewControllers:
- Override didReceiveMemoryWarning (release easily re-created resources, for example, CoreData / Realm objects, pictures, etc.)
- Override viewWillAppear (for creating resources) and viewDidDisappear (to release them)

Alexander Khitev
- 6,417
- 13
- 59
- 115