One reason that developing software for mobile devices can be so much more challenging than developing for desktops/laptops or other hardware, according to ThoughtBot’s Steff Kelsey, is that resources are extremely limited, especially memory. Because of this, Out-of-Memory exception errors (OOMs) are common on iOS, especially if you’re dealing with large files in your app or lots of images.
What makes this double hard for mobile is there are out-of-app elements out of your control, like memory devoured by other apps.
What is an “OOM”?
Historically, an OOM is anytime an app closed abruptly because of the OS decided to close the app for overuse of memory. In mobile, “OOM” has become a generic term to connote any time an app closes that is not a crash or force termination. At Embrace, we found a true “OOM” directly correlates to memory usage AND how often and long the CPU is pegged.
Consider the Curious Case of the iPad
Every app, especially in eCommerce, thinks of iPads incorrectly. Because iPads have larger screens and often better resolution, the initial impetus is to display more images and at higher resolutions. Wrong! iPads actually have less memory and poorer CPUs. This extra imagery causes overuse of memory and always to an abrupt close of the app due to the OS shutting down the app.
What Can Be Done to Eliminate OOMs?
Broadly speaking, reducing an app’s total memory usage is crucial to minimizing OOMs.
- Improper use of UIImage. This can result in too many images being held in memory at the same time. Therefore, destroy images hogging resources can help eliminate OOM errors.
- Retain cycles in View Controllers. This happens when one object strongly references a view controller in such a way that it can cause a loop. Breaking excessive loops is another fix.
- Setting the in-memory cache to scale with the size of the images it’s initialized to contain—whether using FastImageCache or otherwise—can prevent the device resources and RAM from being used up.
- React Native hints and tips – Lots of good stuff in here!
Will This Be Enough?
One thing that can be troubling is that many of these problems only become visible after your app has been released into the wild. As developers, we try to deploy on a number of test devices, but even the best QA approaches can be limited in the number of devices tested, and can never truly simulate real world, real user conditions. Ultimately, an app can get to end user devices that may not have been profiled. Experienced development processes and code reviews can prevent these issues, but additional tools are always helpful. 🙂
Deliver incredible mobile experiences with Embrace.
Get started today with 1 million free user sessions.Get started free