memory-leak-audit

Audit TypeScript code for memory leaks using VS Code disposable patterns.

Updated Apr 28, 2026
Ready to run
npx skills add https://github.com/CokiStudios/cokistudios.github.io --skill memory-leak-audit-cokistudios
💬 Prompt for ChatGPT / Claude Chat▼
Please help me install this Agent Skill.
Skill: memory-leak-audit
Source: https://github.com/CokiStudios/cokistudios.github.io/tree/main/vscode-src/.github/skills/memory-leak-audit
Command: npx skills add https://github.com/CokiStudios/cokistudios.github.io --skill memory-leak-audit-cokistudios

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Event listeners, DOM handlers, and lifecycle callbacks that are never disposed cause listener counts and heap usage to grow over time, producing hard-to-diagnose memory leaks in long-running applications. ## Core Features & Use Cases - Six-Step Audit Checklist: Systematically reviews DOM event listeners, one-time events, repeated method calls, model-tied DisposableStores, resource pools, and test validation. - Concrete Fix Patterns: Provides before/after TypeScript examples for addDisposableListener, Event.once, MutableDisposable, DisposableStore, and onWillDispose. - Use Case: When a terminal find widget leaks one listener per search, apply the MutableDisposable pattern so repeated startSearch() calls keep at most one active listener. ## Quick Start Review this TypeScript file for memory leaks and disposable issues, checking event listeners, lifecycle callbacks, and repeated method calls against the audit checklist.

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 .onclick assignments with addDisposableListener and register the result via this._register(). For one-time lifecycle events, wrap the event with Event.once() so the listener auto-removes after the first invocation.

What is the difference between MutableDisposable and DisposableStore?▼

MutableDisposable holds at most one disposable, replacing the previous value on each assignment, which suits methods called repeatedly. DisposableStore collects multiple disposables and releases them all together, typically tied to a model or object lifetime.

Why do listeners leak when registered in methods called multiple times?▼

Calling this._register() inside a non-constructor method adds a new listener to the class store on every invocation, so counts grow linearly. Use a MutableDisposable field or return an IDisposable to the caller instead.

How do I verify a memory leak fix in tests?▼

Call ensureNoDisposablesAreLeakedInTestSuite() in the test suite to automatically track disposables. Also compare listener counts before and after repeated operations and confirm object counts stabilize rather than growing with usage.

When should I use Event.once instead of a regular event subscription?▼

Use Event.once for events that should fire only once, such as disposal, close, or first-change notifications. A regular subscription stays registered forever after the first fire, leaking the listener and its captured references.