Reducing FOOMs in the Facebook iOS app

Visit the post for more.

Grzegorz Pstrucha
8 min readintermediate
--
View Original

Overview

The article discusses Facebook's efforts to reduce out-of-memory crashes (FOOMs) in their iOS app, detailing the strategies implemented to enhance app stability and reliability. Key methods included profiling memory usage, migrating to WKWebView, and developing an in-app memory profiler to track object allocations.

What You'll Learn

1

How to identify and log out-of-memory events in iOS applications

2

Why migrating from UIWebView to WKWebView can improve memory management

3

How to implement an in-app memory profiler for tracking Objective-C object allocations

Prerequisites & Requirements

  • Understanding of memory management in iOS applications
  • Familiarity with Apple's Instruments application for profiling(optional)

Key Questions Answered

What are FOOMs and how do they affect the Facebook iOS app?
FOOMs, or foreground out-of-memory crashes, occur when the app consumes too much memory, leading to unexpected termination. This can happen without warning, making it indistinguishable from a native crash, which frustrates users.
How did Facebook reduce the number of OOM crashes in their iOS app?
Facebook reduced OOM crashes by profiling memory usage, migrating to WKWebView, and implementing an in-app memory profiler. These strategies helped identify memory leaks and optimize memory allocation, leading to a significant decrease in crashes.
What role does the CT-Scan infrastructure play in preventing memory leaks?
The CT-Scan infrastructure logs resident memory usage in the app, allowing Facebook to detect and flag regressions in memory consumption. This proactive approach helps maintain lower OOM rates during app updates.
What optimizations were made to improve memory allocation patterns?
Facebook observed that reducing temporary memory allocations and holding onto memory rather than repeatedly allocating and deallocating improved app reliability. This change reduced OOM crashes by up to 30 percent in certain scenarios.

Key Statistics & Figures

Reduction in OOM crashes after migrating to WKWebView
Significant
This change led to a noticeable decrease in user reports of app crashes.
Reduction in OOM crashes by optimizing memory allocation patterns
Up to 30 percent
This was achieved by eliminating temporary allocations during CPU activity.

Technologies & Tools

Frontend
Wkwebview
Used to manage web content in a separate process, reducing memory usage in the app.
Tools
Ct-scan
Infrastructure for logging memory usage and detecting regressions.
Tools
Instruments
Apple's profiling tool used to analyze memory usage patterns.

Key Actionable Insights

1
Implement an in-app memory profiler to track object allocations in your iOS app.
This allows you to monitor memory usage in real-time and identify potential leaks, which can significantly enhance app stability.
2
Migrate from UIWebView to WKWebView to better manage memory in your app.
WKWebView runs in a separate process, reducing the memory footprint of your app and improving its chances of staying alive during low-memory events.
3
Regularly log and analyze memory usage patterns to catch regressions early.
Using tools like CT-Scan can help you identify when memory usage spikes occur, allowing for timely fixes before they affect users.

Common Pitfalls

1
Failing to properly manage memory can lead to increased OOM crashes.
This often happens when developers do not track memory allocations and deallocations, resulting in leaks that accumulate over time.
2
Neglecting to test on lower-memory devices can mask OOM issues.
Testing primarily on high-memory devices may lead to overlooking critical memory management issues that only appear on constrained devices.

Related Concepts

Memory Management In Ios
Profiling Tools
Web View Technologies