Agent skill · software engineering · microsoft

memory-leak-audit

Audit code for memory leaks and disposable issues. Use when reviewing event listeners, DOM handlers, lifecycle callbacks, or fixing leak reports. Covers addDisposableListener, Event.once, MutableDisposable, DisposableStore, and onWillDispose patterns.

Why this skill is useful

Adds specific patterns and executable code snippets for preventing memory leaks in event-driven architectures that the AI wouldn't reliably generate on its own.

What it needs

About 3k tokens when loaded. Last updated 2026-08-07. 188,455 stars on the source repository.

What this skill does

Memory Leak Audit The #1 bug category in VS Code. This skill encodes the patterns that prevent and fix leaks. When to Use Reviewing code that registers event listeners or DOM handlers Fixing reported memory leaks (listener counts growing over time) Creating objects in methods that are called repeatedly Working with model lifecycle events (onWillDispose, onDidClose) Adding event subscriptions in constructors or setup methods Audit Checklist Work through each check in order. A single missed pattern can cause thousands of leaked objects. Step 1: DOM Event Listeners Rule: Never use raw .onload, .onclick, or addEventListener() directly. Always use addDisposableListener(). Validated by: PR #280566 — Extension icon widget leaked 185 listeners after 37 toggles. Step 2: One-Time Events Rule: Use Event.once() for events that should only fire once (lifecycle events, close events, first-change events). Validated by: PRs #285657, #285661 — Terminal lifecycle hacks replaced with Event.once(). Step 3: Repeated Method Calls Rule: Objects created in methods called multiple times must NOT be registered to the class this.register(). Use MutableDisposable or return IDisposable to the caller. When the event should only fire once per method call, combine Event.once() with MutableDisposable — this auto-removes the listener after the first invocation while still guarding against repeated calls: Validated by: PR #283466 — Terminal find widget leaked 1 listener per search. Step 4: Model-Tied DisposableStores Rule: When creating a DisposableStore tied to a model's lifetime, register model.onWillDispose(() => store.dispose()) to the store itself. Validated by: Pattern used in chatEditingSession.ts, fileBasedRecommendations.ts, testingContentProvider.ts. Step 5: Resource Pool Patterns Rule: When using factory methods that create pooled objects (lists, trees), disposables must be registered to the individual item, not the pool class. …

How to use it

Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:

@skills microsoft/memory-leak-audit

View the source on GitHub

Browse the @skills marketplace