memory-leak-audit

Audit TypeScript code for memory leaks in event listeners and disposable patterns.

10|1|Updated Jul 13, 2026
One-click install
npx skills add https://github.com/KevinHuangIsLearning/shortestpath-ide --skill memory-leak-audit-kevinhuangislearning
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: memory-leak-audit
Source: https://github.com/KevinHuangIsLearning/shortestpath-ide/tree/main/.github/skills/memory-leak-audit
Command: npx skills add https://github.com/KevinHuangIsLearning/shortestpath-ide --skill memory-leak-audit-kevinhuangislearning

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Event listeners and disposable objects that are never released cause memory leaks that grow with usage, degrading editor performance over time. This Skill provides a systematic checklist to detect and fix the most common leak patterns in VS Code-style TypeScript codebases. ## Core Features & Use Cases - Six-step audit checklist: Covers DOM event listeners, one-time events, repeated method calls, model-tied DisposableStores, resource pools, and test validation. - Pattern-based fixes: Each check pairs an anti-pattern with the correct API, including addDisposableListener, Event.once, MutableDisposable, DisposableStore, and onWillDispose. - Real-world validation: Every rule is backed by actual merged PRs that fixed production leaks, such as listener leaks in terminal find widgets and chat content pools. - Use Case: When a bug report says listener counts grow after repeated searches, use this Skill to identify that startSearch() registers listeners to the class store and fix it with MutableDisposable. ## Quick Start Review this file for memory leaks using the memory leak audit checklist and fix any disposable pattern violations you find.

Frequently Asked Questions about memory-leak-audit

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix memory leaks from event listeners in TypeScript?▼

Replace raw addEventListener or property handlers like .onclick with addDisposableListener, and register the result via this._register(). For one-time events, wrap the emitter with Event.once() so the listener auto-removes after firing.

What is MutableDisposable and when should I use it?▼

MutableDisposable is a container that holds at most one disposable, replacing the previous one when reassigned. Use it in methods called repeatedly, like startSearch(), instead of this._register(), which would accumulate a new listener on every call.

How do I detect memory leaks in VS Code extension tests?▼

Call ensureNoDisposablesAreLeakedInTestSuite() at the top of your test suite. It automatically tracks disposables created during tests and fails the suite if any are not disposed, catching leaks before they ship.

Why do listeners leak when registered inside repeated method calls?▼

Registering a listener with this._register() inside a method adds it to the class-level store on every invocation, and it is only released when the class is disposed. Use MutableDisposable or return an IDisposable to the caller instead.

How do I tie a DisposableStore to a model's lifecycle?▼

Register model.onWillDispose(() => store.dispose()) inside the store itself via store.add(). This guarantees the store and all its listeners are cleaned up exactly when the model is destroyed, preventing orphaned subscriptions.