Reputation: 6186
If i got three ViewControllers called VC1, VC2, VC3. And in every ViewController
, there is lots of ImageViews
.
If i navigate these ViewControllers like this with pushViewController
method:
VC1 -> VC2 -> VC3
So does the memory of image allocated in VC1 will be released? If not, did we need to release and load image in VC1 when navigating to save memory?
Upvotes: 1
Views: 126
Reputation: 169
If you use navigationController?.pushViewController()
function all your view controllers are retained by navigationController. It has property viewControllers
where you can find all the view controllers. Thus you have to do memory management by yourself. You could remove images from the image views in viewWillDisappear()
function of your view controller and assign them again in the viewWillAppear
function.
Upvotes: 2
Reputation: 535249
Use Instruments to determine you are in fact having memory issues. If so, then yes, you might try deliberately setting images to nil
when you navigate away from a view controller. But first you should ask yourself why you are having memory issues. A common mistake is to use big images to display in a small UIImageView; never do that. Always resize your images to be no bigger than needed for display. If you do, it's unlikely you'll experience any memory pressure.
Upvotes: 3