Join CTO Moataz Soliman as he explores the potential impact poor performance can have on your bottom line. 👉 Register Today

ebook icon

App Performance

General

What are Out Of Memory (OOM) Crashes and How to Avoid Them

When it comes to your app's user experience, nothing is more disruptive and frustrating to your users than app crashes. In fact, crashes are so disruptive that 53% of users uninstall apps that crash, and 80% of users will give a problematic app less than three tries before uninstalling it. But developers are already aware of the impact app crashes can have on their users and actively try to avoid, detect, and fix them with the help of various tools.

However, there is another type of error that can be just as disruptive as app crashes but has nevertheless relatively managed to fly under the radar. While an out-of-memory (OOM) error is not technically a crash, nine times out of ten your users will not know the difference. This is why many developers tend to call them OOM crashes.

So, what exactly are OOMs and how do they impact your app's experience? Read on for the answer to these questions as well as a few tips to avoid them altogether.

What are OOMs?

As might be evident from their name, OOMs occur when the OS decides to terminate your app to free up the memory it uses. OOMs are further divided into background OOMs (BOOMs) and foreground OOMs (FOOMs) depending on the app's state when they occur.

BOOMs are more often caused by the app in the foreground consuming excess memory than by excessive memory use by an app or apps in the background. You generally have no control over BOOMs, but they also have a minimal impact on your app's UX since your app does not unexpectedly terminate while in the foreground where users can see it.

FOOMs are usually what people are referring to when they talk about OOMs and these are the ones that are caused by your app using too much memory. They are extremely disruptive to the user experience, but the good news is you can largely avoid them with some efficient memory management.

Avoiding OOM crashes

As mentioned earlier, avoiding OOM "crashes" in your app really boils down to making sure that your app is using, retaining, and freeing memory in an efficient manner. Here are some tips and best practices you can use to reduce your app's memory footprint and eliminate OOMs.

Know your limits

Before you start worrying about how much memory your app is going to use, you must first understand how much memory you have available to work with. This of course means that you have to think carefully about which devices you want your app to support. Next, you need to find out the memory threshold at which the OS decides to terminate your app. This tool from developer Jan Ilavsky can help you do just that, and you can check this StackOverflow post for the results of all iOS devices till the iPhone 11 Pro Max.

Plug your leaks

Memory leaks are one of the main culprits that can cause an OOM, especially retain cycles. Retain cycles occur when two or more objects hold a strong reference to each other causing them to remain held in memory indefinitely. You can check out this great post from DoorDash about how they found and fixed retain cycles in their iOS app.

Don't cache out

The cache can be a great friend when you use it for frequently accessed objects that use a lot of memory, but if you abuse it and start caching too many objects you can quickly force the OS to terminate your app. Images are a prime example of objects that can eat up your cache quickly. You should always purge your cache of objects that use a lot of memory once they're not needed and preferably apply a limit to your cache size.

Track your OOM rate

Reducing your app's memory footprint is great but it is of little use if you can't actually see the effect it is having. Detecting and tracking OOM crashes that occur in your app and profiling your app's memory usage is the best way to see if your memory optimization is working and has the desired effect. Using a tool like Instabug that can detect and report OOMs will help you keep track of them and see the result of your efforts.

For more tips on reducing your memory footprint and optimizing its usage, you can check out this post.

Learn more:

Instabug empowers mobile teams to maintain industry-leading apps with mobile-focused, user-centric stability and performance monitoring.

Visit our sandbox or book a demo to see how Instabug can help your app

Seeing is Believing, Start Your 14-Day Free Trial

In less than a minute, integrate the Instabug SDK for iOS, Android, React Native, Xamarin, Cordova, Flutter, and Unity mobile apps