memory-leak-audit

Audit TypeScript code for memory leaks and disposable lifecycle issues.

Updated Apr 14, 2026
One-click install
npx skills add https://github.com/jimeh/hucode --skill memory-leak-audit-jimeh
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: memory-leak-audit
Source: https://github.com/jimeh/hucode/tree/main/.github/skills/memory-leak-audit
Command: npx skills add https://github.com/jimeh/hucode --skill memory-leak-audit-jimeh

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Event listeners, DOM handlers, and disposables that are never released cause listener counts and heap usage to grow over time, producing the most common bug category in VS Code-style codebases. This Skill provides a systematic checklist to find and fix those leaks during code review or when investigating leak reports. ## 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 Library with Fixes: Each check pairs an anti-pattern with the correct pattern using addDisposableListener, Event.once, MutableDisposable, DisposableStore, and onWillDispose. - Use Case: A terminal find widget leaks one listener per search. The audit identifies the repeated-method-call pattern, replaces this._register() with a MutableDisposable, and adds ensureNoDisposablesAreLeakedInTestSuite() to the test suite to prevent regression. ## Quick Start Review this TypeScript file for memory leaks and disposable lifecycle issues using the memory leak 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 find memory leaks in TypeScript event listeners?▼

Work through a checklist covering DOM listeners, one-time events, repeated method calls, model lifecycle stores, and pooled objects. Replace raw addEventListener with addDisposableListener and verify listener counts stabilize after repeated operations.

How to fix listeners leaking in methods called repeatedly?▼

Do not register disposables to the class store inside methods called multiple times. Use a MutableDisposable field so each call replaces the previous listener, or return an IDisposable to the caller for explicit cleanup.

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

Use Event.once for lifecycle events that should fire only once, such as dispose, close, or first-change events. It automatically removes the listener after the first invocation, preventing permanent registrations.

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

Call ensureNoDisposablesAreLeakedInTestSuite() in every test suite that creates disposable objects. It tracks disposables automatically and fails the suite if any are not released.

Why do pooled objects like lists and trees leak disposables?▼

Factory methods that register listeners to the pool class never clean up per item. Each pooled item needs its own DisposableStore so disposal happens when the individual item is released, not the pool.