BlogsMetaJavaScript Memory Leak Detection Framework

JavaScript Memory Leak Detection Framework

JavaScript Memory Leak Detection Framework

2
posts
2016–2022

Meta has open-sourced MemLab, a JavaScript memory testing framework that automates memory leak detection. MemLab helps engineers and developers identify and root-cause memory leaks in web applications by running headless browsers through predefined test scenarios, diffing JavaScript heap snapshots, generating retainer traces, and clustering them for analysis. It provides a graph-view API for JavaScript heaps and supports memory assertions for self-memory checking in Node.js or Jest tests. Meta has also developed and open-sourced FBRetainCycleDetector, FBAllocationTracker, and FBMemoryProfiler for automatic memory leak detection on iOS, leveraging Objective-C's runtime for retain cycle analysis and providing tools for both automated and manual profiling.

2022

MemLab: An open source framework for finding JavaScript memory leaks

9/12/2022

This post introduces MemLab, an open-source JavaScript memory testing framework. It details the motivation for developing MemLab due to increasing memory usage and OOM crashes in Meta's SPAs, the technical challenges of memory leaks in JavaScript, and the six-step process MemLab uses for leak detection (browser interaction, heap diffing, leak refinement, retainer trace generation, clustering, and reporting). It also highlights MemLab's features: automated leak detection via test scenarios, a memory-efficient graph-view API for JavaScript heaps, memory assertions for testing, and a memory toolbox with CLI commands and APIs for optimization.

2016

Automatic memory leak detection on iOS

4/13/2016

This post details the development and open-sourcing of three tools for automatic memory leak detection on iOS: FBRetainCycleDetector, FBAllocationTracker, and FBMemoryProfiler. FBRetainCycleDetector uses Objective-C's runtime introspection (ivar layouts, type encoding) and a block ABI analysis (with release detectors) to find retain cycles. FBAllocationTracker proactively tracks object allocations/deallocations to provide candidate objects for the detector. FBMemoryProfiler offers manual profiling with 'generation tracking'. The post also describes a backend algorithm for clustering retain cycles and using 'git/hg blame' to identify the likely introducer of a leak.