I have a scrollview containing multiple UIImageViews that are kept in an array. Each of these UIImageViews has the same background image, but a unique mask. When these images are not displayed on the screen, I want to remove the mask to save memory. A function like the following is called when the mask has to be created or deleted. In this case however, the memory footprint will not decrease when the imageView mask is set to nil.
func updateView(imageName: String, imageView: UIImageView, show: Bool)
if show {
let newMask = UIImageView()
newMask.image = UIImage(named: imageName)
newMask.frame = frame
imageView.mask = newMask
} else {
imageView.mask = nil
}
}
How to solve this problem? As a beginner I've been looking for the answer for days and any help would be very much appreciated.