memory-leak-audit

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

1|Updated Apr 8, 2026
One-click install
npx skills add https://github.com/voidful/Aixlarity --skill memory-leak-audit-voidful
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: memory-leak-audit
Source: https://github.com/voidful/Aixlarity/tree/main/aixlarity-ide/.github/skills/memory-leak-audit
Command: npx skills add https://github.com/voidful/Aixlarity --skill memory-leak-audit-voidful

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Event listeners and disposable objects that are never released cause memory leaks where listener counts grow with every operation, degrading editor performance over time. This Skill provides a systematic checklist to find and fix these leaks 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 Library with Fixes: Each check pairs an anti-pattern with the correct pattern, such as replacing raw addEventListener with addDisposableListener, or using MutableDisposable for listeners registered in repeatedly-called methods. - Real-World Validation: Every rule is backed by a merged VS Code pull request (e.g., PR #280566, #283466) showing the actual leak it fixed. - Use Case: A terminal find widget leaks one listener per search. The audit identifies the repeated-method-call pattern and fixes it by storing the listener in a MutableDisposable so at most one listener exists at a time. ## Quick Start Review this TypeScript 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 lifecycle events, wrap the event with Event.once() so the listener auto-removes after firing.

How to prevent listener leaks in methods called multiple times?

Do not register listeners to the class store inside repeatedly-called methods. Instead, hold a MutableDisposable field and assign the new listener to its .value property, which disposes the previous listener and guarantees at most one active registration.

What is the difference between MutableDisposable and DisposableStore?

MutableDisposable holds at most one disposable, replacing the old one when reassigned, which suits repeated registrations. DisposableStore holds many disposables and releases them all at once, which suits grouping resources tied to a single lifetime such as a model.

How do I test for disposable leaks in VS Code extensions?

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 without manual listener counting.

Why do pooled objects like lists and trees leak disposables?

Factory methods that register item listeners to the pool class accumulate one registration per created item, and pooled items are reused rather than disposed. Fix this by giving each item its own DisposableStore and returning an item-scoped dispose method.