the Chromium logo

The Chromium Projects

Leak Detection

When launching a new feature it is important to consider doing manual inspection to look for memory leaks since some types of leaks will not easily show up during other testing, especially if they are slow leaks. This can avoid bugs which are otherwise difficult to detect.

You can look for memory leaks on Windows using ETW heap tracing using UIforETW, an open-source wrapper for Microsoft's ETW/WPT toolkit. To set up for heap tracing you need to download and run UIforETW, then:

Tips for efficient tracing:

These trace analysis instructions are very terse because a full explanation would require many pages. If you need assistance then please contact brucedawson@chromium.org.

If you have Python installed then IdentifyChromeProcesses.py will be run and a list of Chrome process types and PIDs will be printed, which helps with identifying the browser process, etc. If you need to identify a specific render process PID then use Chrome's Task Manager. You can copy the trace to a different machine for analysis, and you can manually run IdentifyChromeProcesses.py on that machine by right-clicking on the trace name and selecting Scripts-> Identify Chrome Processes.

Open the trace in WPA. The default view is designed for analyzing performance rather than allocations so you will want to use HeapAnalysis.wpaProfile from UIforETW's bin directory (available in versions published in September 2018 or later). You can apply this profile by going to the Profiles menu in WPA, selecting Apply... and then browsing to the .wpaProfile file. Load symbols (Trace-> Load Symbols) and you can then drill down into the allocations for the process of interest. The Type column will usually list AIFI and AIFO types. AIFI means Allocated Inside and Freed Inside - meaning that the allocation was transient within the visible time range. AIFO means Allocated Inside and Freed Outside meaning that the memory was allocated but not freed within the visible time range. AIFO allocations are potential leaks. You can drill down through the stack, sorting by Count, or Size, or you can search for particular symbols by typing Ctrl+F when the Stack column is selected.

The allocation times for the selected portion of stack will be highlighted in the graph area, giving clues to patterns. These can be compared against input events emitted by UIforETW.exe.

It is also possible to use Visual Studio's heap profiler. This is particularly convenient for profiling the browser process at startup.