Angular Memory Leaks: A Guide for Developers & Decision-Makers to Optimize Performance
Last week I worked on memory leaks in our Angular application. Today is not about why memory leaks were introduced, but rather about how to find and fix them.
Memory leaks were identified using Chrome DevTools. The Memory tab is especially useful for this. I repeatedly followed these steps:
It’s best to do this in incognito mode, remove all console.log / warn / debug / info logs to avoid console retainers. Ideally, use a production build—but that usually means losing source maps and therefore traceability.
Snapshot comparison
Snapshot 1 → 2: 🙈
Snapshot 2 → 3: ✅
🔁 Tip: Repeat the leaking scenario multiple times. This makes it easier to detect patterns. For example, if you run it 5 times, look for deltas like 5, 10, 15… since components may be instantiated multiple times.
Recommended by LinkedIn
Common sources of memory leaks
Another important aspect is presenting the results. 📈
For this, I created a Playwright performance test that runs the leaking scenario 100 times and reads the memory heap after each iteration via the Chrome DevTools Protocol (CDP). From that, I generated a JSON file and used Chart.js to build a chart (the one from the article background)
I’m very proud of the result. Any experienced web developer knows that memory leaks are a difficult topic—and the achieved result is excellent.
A normal heap flow looks like a sawtooth pattern (similar to stop-and-go traffic): memory grows, then the garbage collector runs and frees it, and this repeats indefinitely. With memory leaks, however, you get a growing sawtooth pattern—more like a staircase.
❓ I’m pretty sure that almost every larger web project has memory leaks. How do you deal with them? Do you have tests to detect them? I’d love to hear about your experiences. ❓❓
Written with ❤️ by human. Translated by AI.