Fix memory problems

Kayce Basques
Kayce Basques

Learn how to use Chrome and DevTools to find memory issues that affect page performance, including memory leaks, memory bloat, and frequent garbage collections.

Summary

  • Find out how much memory your page is using with the Chrome Task Manager.
  • Visualize memory usage over time with Timeline recordings.
  • Identify detached DOM trees (a common cause of memory leaks) with Heap Snapshots.
  • Find out when new memory is being allocated in your JS heap with Allocation Timeline recordings.
  • Identify detached elements retained by JavaScript reference.

Overview

In the spirit of the RAIL performance model, the focus of your performance efforts should be your users.

Memory issues are important because they are often perceivable by users. Users can perceive memory issues in the following ways:

  • A page's performance gets progressively worse over time. This is possibly a symptom of a memory leak. A memory leak is when a bug in the page causes the page to progressively use more and more memory over time.
  • A page's performance is consistently bad. This is possibly a symptom of memory bloat. Memory bloat is when a page uses more memory than is necessary for optimal page speed.
  • A page's performance is delayed or appears to pause frequently. This is possibly a symptom of frequent garbage collections. Garbage collection is when the browser reclaims memory. The browser decides when this happens. During collections, all script execution is paused. So if the browser is garbage collecting a lot, script execution is going to get paused a lot.

Memory bloat: how much is "too much"?

A memory leak is easy to define. If a site is progressively using more and more memory, then you've got a leak. But memory bloat is a bit harder to pin down. What qualifies as "using too much memory"?

There are no hard numbers here, because different devices and browsers have different capabilities. The same page that runs smoothly on a high-end smartphone might crash on a low-end smartphone.

The key here is to use the RAIL model and focus on your users. Find out what devices are popular with your users, and then test out your page on those devices. If the experience is consistently bad, the page may be exceeding the memory capabilities of those devices.

Monitor memory use in realtime with the Chrome Task Manager

Use the Chrome Task Manager as a starting point to your memory issue investigation. The Task Manager is a real-time monitor that tells you how much memory a page is using.

  1. Press Shift+Esc or go to the Chrome main menu and select More tools > Task manager to open the Task Manager.