The problem of my app is that the memory usage keeps rising. I have an app that uses multiple UITableView how it is set up is as follows:
UITableView 1 leads into UITableView 2
UITableView 1 leads into UITableView 3
UITableView 1 leads into UITableView 4
UITableView 1 leads into UITableView 5
UITableView 1 leads into UITableView 6
All the Cells in UITableView 2,3,4,5 and 6 all have contain images. When I enter UITableView 2,3,4,5 and 6 the memory usage raises as expected as the app loads the images. When I then dismiss the UITableview that I am in and enter another UITableview the memory usage continues to rise.
What I want to do is clear the memory when I dismiss a UITableview 2,3,4,5 or 6. This will mean that the memory usage wont keep on building.
I am currently dismissing the UITableView using the following:
@IBAction func Back(_ sender: Any) {
NotificationCenter.default.removeObserver(self)
self.dismiss(animated: true, completion: nil)
}
Images are stored in a folder in the app. The names of the images are stored in an array this array in my case is called foodImageArray
. The UItableView images populated in order, by reading the array and linking each cell to its corresponding image.
cell.foodImage.image = UIImage(named: foodImageArray[indexPath.row] + ".jpg")