why is UIImage(contentsOfFile: "path") retaining memory

The memory used jumps to 498 megs when image is loaded but not displayed and drops to 242 megs when viewcontroller is dropped with nav controllers back button.

UIImage(contentsOfFile: is not supposed to cache, i assume that is where the 240 meg drop is from, but why is half of memory used, 240 megs, being retained?

func  save_ImageJPG() -> Bool {

        // load tif from app folder image approx 8000 x 6000 pixels         let s  = currentMap_Name.replacingOccurrences(of: " ", with: "%20")

        let filePath = getDocumentsDirectory().appendingPathComponent("Folder" ).appendingPathComponent(s)

        let image = UIImage(contentsOfFile: filePath.path)         // change file type to jpg         let f = URL(string: s)?.deletingPathExtension().absoluteString

        let e = URL(string: f! + ".jpg")?.absoluteString         let path = getDocumentsDirectory().appendingPathComponent("TempFolder"         ).appendingPathComponent(e!)

        if !FileManager.default.fileExists(atPath: path.path) {             let jpgData = (image!.jpegData(compressionQuality: 1.0)!)             try? jpgData.write(to: path)             return true         }             return false     }

or is the let jpgData = (image!.jpegData(compressionQuality: 1.0)!) retaining memory?

Please can you put your code into a code block (using "Paste and Match Style"), to make it more readable?

func save_ImageJPG() -> Bool { // load tif from app folder image approx 8000 x 6000 pixels let s = currentMap_Name.replacingOccurrences(of: " ", with: "%20") let filePath = getDocumentsDirectory().appendingPathComponent("Folder" ).appendingPathComponent(s) let image = UIImage(contentsOfFile: filePath.path) // change file type to jpg let f = URL(string: s)?.deletingPathExtension().absoluteString let e = URL(string: f! + ".jpg")?.absoluteString let path = getDocumentsDirectory().appendingPathComponent("TempFolder" ).appendingPathComponent(e!) if !FileManager.default.fileExists(atPath: path.path) { let jpgData = (image!.jpegData(compressionQuality: 1.0)!) try? jpgData.write(to: path) return true } return false }

To format the code correctly, you need to paste it into the original question, or a new reply, not a comment.

why is UIImage(contentsOfFile: "path") retaining memory
 
 
Q