Reducing Memory Footprint When Using UIImage
With a simple approach recommended by the Apple engineers
This article is originally published at https://swiftsenpai.com on December 1, 2020.
Recently my team and I are working on an image processing app for a client. The app works pretty well on most of the aspects. Unfortunately, when we start loading HD images on screen, the app will crash occasionally due to “out of memory exception”.
In this article, I would like to share with you the problem we are facing, what is the root cause of the high memory usage and how we manage to reduce the app’s memory footprint using a simple fix recommended by the Apple engineers.
The Problem
As mentioned earlier, our app’s memory usage spikes up pretty high when we start loading HD images on screen. To showcase the problem we are facing, I have created a sample app that loads an HD image onto the image view when a button is tapped.