Course contentsShow
← JavaScript
Lesson 1890 of 2,72339. Memory Management and GCFree lesson

Using Allocation Instrumentation on Timeline

Recording allocations over time to see which functions are creating objects that aren't being freed.

Using Allocation Instrumentation on Timeline

You'll learn how to record live memory allocations over time to pinpoint exactly when and where objects are being created but never freed.

What It Does

While heap snapshots give you static pictures of memory, Allocation Instrumentation on Timeline is like a video recording. It captures every allocation as your application runs, showing you a timeline of which functions are creating objects moment-by-moment. This makes it much easier to correlate memory growth with specific user actions or code paths.

How It Works

In Chrome DevTools Memory Profiler, select "Allocation instrumentation on timeline" and click "Start." The tool begins recording every object allocation with stack traces. As you interact with your app, you'll see blue bars appear on the timeline—each representing allocations at that moment.

The genius here: after interacting (like clicking buttons, loading data), if those blue bars remain tall and don't shrink, you've found objects that were allocated but never garbage collected. Click on any bar to see the constructor and stack trace that created those objects.

The Detective Work

Think of this as surveillance footage for memory. If you notice the timeline growing steadily upward during a specific action—say, opening and closing a modal repeatedly—you can click into that time period and see exactly which functions allocated the leaked objects. You'll see the call stack that led to the allocation, often revealing forgotten event listeners or closures holding references.

This is far more powerful than snapshot comparison because you see the cause and effect relationship between your actions and memory growth in real-time.

Key Takeaway: Allocation Instrumentation on Timeline records live allocations as you interact with your app, revealing exactly which functions create objects that never get freed—making leak detection surgical rather than guesswork.