Reputation: 3526
I'm new and earning my into IOS Application Development and let me tell you I don't know a single bit about Memory and Memory Management . While I Was playing with tabViewController I make two tabs and three ViewController and connect them via NavigationalController and link them as a cycle like:-
navigationController1
firstViewController -> secondViewController -> thirdViewController -> firstViewController
navigationController2
firstViewController -> secondViewController -> thirdViewController -> firstViewController
and run them on Simulator and noticed that as soon as I getting the ViewControllers on the Stack the Memory was increasing by .1 MBs.
than I add a Single Image of size 4.5 MB on the firstViewController (NavigationController1) and run the App suddenly I Noticed that the Memory reached to 66 Mb
As the App starts and as I add the viewControllers on the stack the memory was increasing at the same rate like the last time (.1 MBs) I don't understand the reason behind it and whats the logic of the whole seen ?
"And my apologies for the reason buttons are not showing in the tabBar there are two title on the tabBar Navigation1 and Navigation2 also the button has the method to push views "
Upvotes: 1
Views: 199
Reputation: 1044
When an image is loaded into memory it gets uncompressed. While a compressed image might not require more than 4.5 MB for a high resolution (for instance by saving as JPEG), it's uncompressed size might me a lot higher. Even if the UIImageView
is just a part of the screen, or even off-screen, it still requires an amount of memory based on the original resolution of the image.
Also, you have a view controller loop here. Once you go from VC1 -> VC2 -> VC3 -> VC1 you will not get your original instance of VC1 back for the last one, but a new instance, meaning that you will have a total of 4 view controllers in memory at the same time. What you should do to go from VC3 and back to VC1 is to pop the view controller stack instead of adding another instance of VC1. You can do this by calling self.navigationController?.popToRootViewControllerAnimated(true)
on VC3.
Upvotes: 1