You can track this imageView in some property, and if you want to remove it, you simply:
imageView.removeFromSuperview()
BTW, as you know, UIImage(named:...) will cache images in memory. If you want this, fine, but if not, you can use UIImage(contentsOfFile:...) with the full path to this resource. If you use UIImage(named:...) , the image will remain in memory even after deleting the UIImageView . As the documentation says:
If you have an image file that will be displayed only once, and you want to make sure that it is not added to the system cache, you must create your image using imageWithContentsOfFile: This will save a one-time image from the system cache, which will potentially improve the usage characteristics of your application.
source share