microsoft avatar

Memory Leak Audit

This is a checklist-driven audit for catching disposable and event listener leaks in VS Code extension code. You'd reach for it when reviewing code that registers DOM handlers, fixing reported leaks where listener counts grow unbounded, or working with lifecycle callbacks. It walks through six patterns in order: using addDisposableListener for DOM events, Event.once for one-time fires, MutableDisposable for methods called repeatedly, model-tied DisposableStores, resource pool disposal scoping, and test validation. Each rule is validated against actual VS Code PRs where these patterns prevented or fixed real leaks. The practical bit is the sequential checklist format, since missing even one pattern can leak thousands of objects over time.

skills.sh installs
3.2K
GitHub stars
195.3K
last updated
Aug 21, 2026

Install

$ npx -y skills add microsoft/vscode --skill memory-leak-audit --agent claude-code

Installs into .claude/skills of the current project.

Files

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().

// BAD — leaks a listener every call
this.iconElement.onload = () => { ... };

// GOOD — tracked and disposable
this._register(addDisposableListener(this.iconElement, 'load', () => { ... }));

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).

Sponsors

Details

Repository
github.com/microsoft/vscode
Categories
Frontend Development, Debugging
First seen
Apr 16, 2026

More from microsoft/vscode

All 15
1markdown-viewer avatarmindmapmarkdown-viewer/skillsCreate hierarchical mind maps using PlantUML @startmindmap syntax. Best for brainstorming, topic decomposition, study notes, and decision trees with automatic r3.2Kskills.sh installs
2dpearson2699 avatarrelevancekitdpearson2699/swift-ios-skillsIncrease widget visibility on Apple Watch using RelevanceKit. Use when providing contextual relevance signals for watchOS widgets, declaring time-based or locat3.2Kskills.sh installs
3tradermonty avatarparabolic-short-trade-plannertradermonty/claude-trading-skillsScreen US equities for parabolic exhaustion patterns and generate conditional pre-market short plans, then evaluate intraday trigger fires from live 5-min bars.3.1Kskills.sh installs
4mindrally avatarframer-motionmindrally/skillsExpert guidelines for building performant animations with Framer Motion/Motion library in React applications3.1Kskills.sh installs
5browserbase avatarfetchbrowserbase/skillsUse this skill when the user wants to retrieve a URL without a full browser session: fetch HTML or JSON from static pages, inspect status codes or headers, foll3.1Kskills.sh installs
6browserbase avatarbrowser-tracebrowserbase/skillsCapture a full DevTools-protocol trace of any browser automation — CDP firehose, screenshots, and DOM dumps — then bisect the stream into per-page searchable bu3.1Kskills.sh installs