[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M699B1NKH6Y7G21D8H425WN8":3,"skill-same:01M699B1NKH6Y7G21D8H425WN8":64},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":35,"linkOnly":36,"markdownContent":37,"markdownBody":38,"frontMatter":39,"refName":40,"commitSha":41,"skillDirectory":42,"forksCount":43,"repositoryHtmlUrl":44,"repositoryHomepageUrl":45,"ownerHtmlUrl":46,"ownerBlogUrl":47,"ownerDescription":48,"updatedAt":49,"install":50,"resources":63},"01M699B1NKH6Y7G21D8H425WN8","memory-leak-audit",null,"Audit code for memory leaks and disposable issues. Use when reviewing event listeners, DOM handlers, lifecycle callbacks, or fixing leak reports. Covers addDisposableListener, Event.once, MutableDisposable, DisposableStore, and onWillDispose patterns.","microsoft\u002Fvscode","microsoft","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F6154722?v=4","01M698VYDXZ6JW5WH3CRV650R8","Microsoft","01M6998NK2WED5M549DX06VBCH",195347,"MIT","https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002Fvscode\u002Fblob\u002Fmain\u002F.github\u002Fskills\u002Fmemory-leak-audit\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34],"memory","memory leak audit","audit","code","issues","lifecycle","use","reports","patterns","Callbacks","event","audit code","dom","for","listeners","when","2026-11-10 10:12:30",false,"---\nname: memory-leak-audit\ndescription: 'Audit code for memory leaks and disposable issues. Use when reviewing event listeners, DOM handlers, lifecycle callbacks, or fixing leak reports. Covers addDisposableListener, Event.once, MutableDisposable, DisposableStore, and onWillDispose patterns.'\n---\n\n# Memory Leak Audit\n\nThe #1 bug category in VS Code. This skill encodes the patterns that prevent and fix leaks.\n\n## When to Use\n\n- Reviewing code that registers event listeners or DOM handlers\n- Fixing reported memory leaks (listener counts growing over time)\n- Creating objects in methods that are called repeatedly\n- Working with model lifecycle events (onWillDispose, onDidClose)\n- Adding event subscriptions in constructors or setup methods\n\n## Audit Checklist\n\nWork through each check in order. A single missed pattern can cause thousands of leaked objects.\n\n### Step 1: DOM Event Listeners\n\n**Rule**: Never use raw `.onload`, `.onclick`, or `addEventListener()` directly. Always use `addDisposableListener()`.\n\n```typescript\n\u002F\u002F BAD — leaks a listener every call\nthis.iconElement.onload = () => { ... };\n\n\u002F\u002F GOOD — tracked and disposable\nthis._register(addDisposableListener(this.iconElement, 'load', () => { ... }));\n```\n\n**Validated by**: PR #280566 — Extension icon widget leaked 185 listeners after 37 toggles.\n\n### Step 2: One-Time Events\n\n**Rule**: Use `Event.once()` for events that should only fire once (lifecycle events, close events, first-change events).\n\n```typescript\n\u002F\u002F BAD — listener stays registered forever after first fire\nmodel.onDidDispose(() => store.dispose());\n\n\u002F\u002F GOOD — auto-removes after first invocation\nEvent.once(model.onDidDispose)(() => store.dispose());\n```\n\n**Validated by**: PRs #285657, #285661 — Terminal lifecycle hacks replaced with `Event.once()`.\n\n### Step 3: Repeated Method Calls\n\n**Rule**: Objects created in methods called multiple times must NOT be registered to the class `this._register()`. Use `MutableDisposable` or return `IDisposable` to the caller.\n\n```typescript\n\u002F\u002F BAD — every call adds another listener to the class store\nstartSearch() {\n    this._register(this.model.onResults(() => { ... }));\n}\n\n\u002F\u002F GOOD — MutableDisposable ensures max 1 listener\nprivate readonly _searchListener = this._register(new MutableDisposable());\n\nstartSearch() {\n    this._searchListener.value = this.model.onResults(() => { ... });\n}\n```\n\nWhen the event should only fire once per method call, combine `Event.once()` with `MutableDisposable` — this auto-removes the listener after the first invocation while still guarding against repeated calls:\n\n```typescript\nprivate readonly _searchListener = this._register(new MutableDisposable());\n\nstartSearch() {\n    this._searchListener.value = Event.once(this.model.onResults)(() => { ... });\n}\n```\n\n**Validated by**: PR #283466 — Terminal find widget leaked 1 listener per search.\n\n### Step 4: Model-Tied DisposableStores\n\n**Rule**: When creating a `DisposableStore` tied to a model's lifetime, register `model.onWillDispose(() => store.dispose())` to the store itself.\n\n```typescript\nconst store = new DisposableStore();\nstore.add(model.onWillDispose(() => store.dispose()));\nstore.add(model.onDidChange(() => { ... }));\n```\n\n**Validated by**: Pattern used in `chatEditingSession.ts`, `fileBasedRecommendations.ts`, `testingContentProvider.ts`.\n\n### Step 5: Resource Pool Patterns\n\n**Rule**: When using factory methods that create pooled objects (lists, trees), disposables must be registered to the individual item, not the pool class.\n\n```typescript\n\u002F\u002F BAD — registers to pool, never cleaned per item\ncreateItem() {\n    const item = new Item();\n    this._register(item.onEvent(() => { ... }));\n    return item;\n}\n\n\u002F\u002F GOOD — wrap with item-scoped disposal\ncreateItem(): IDisposable & Item {\n    const store = new DisposableStore();\n    const item = new Item();\n    store.add(item.onEvent(() => { ... }));\n    return { ...item, dispose: () => store.dispose() };\n}\n```\n\n**Validated by**: PR #290505 — Chat content parts CollapsibleListPool and TreePool leaked disposables.\n\n### Step 6: Test Validation\n\n**Rule**: Every test suite that creates disposable objects must call `ensureNoDisposablesAreLeakedInTestSuite()`.\n\n```typescript\nimport { ensureNoDisposablesAreLeakedInTestSuite } from '..\u002F..\u002F..\u002F..\u002Fbase\u002Ftest\u002Fcommon\u002Futils.js';\n\nsuite('MyFeature', () => {\n    ensureNoDisposablesAreLeakedInTestSuite();\n\n    test('does something', () => {\n        \u002F\u002F test disposables are tracked automatically\n    });\n});\n```\n\n## Quick Reference\n\n| Scenario | Pattern | Anti-Pattern |\n|----------|---------|-------------|\n| DOM events | `addDisposableListener()` | `.onclick =`, `addEventListener()` |\n| One-time events | `Event.once(event)(handler)` | `event(handler)` for lifecycle |\n| Repeated methods | `MutableDisposable` or return `IDisposable` | `this._register()` in non-constructor |\n| Model lifecycle | `store.add(model.onWillDispose(...))` | Forgetting cleanup |\n| Pooled objects | Item-scoped `DisposableStore` | Pool-scoped `this._register()` |\n| Tests | `ensureNoDisposablesAreLeakedInTestSuite()` | No leak checking |\n\n## Verification\n\nAfter fixing leaks, verify by:\n1. Checking listener counts before\u002Fafter repeated operations\n2. Running `ensureNoDisposablesAreLeakedInTestSuite()` in tests\n3. Confirming object counts stabilize (don't grow linearly with usage)\n4. **For chat-specific leaks**: Run the chat memory leak checker via `pnpm run perf:chat-leak` (see the `chat-perf` skill). It sends N messages in a single session, forces GC between each, and uses linear regression on heap\u002FDOM samples to detect per-message growth. A slope above 2 MB\u002Fmsg indicates a leak. Use `--messages 20 --verbose` for more accurate results.\n","# Memory Leak Audit\n\nThe #1 bug category in VS Code. This skill encodes the patterns that prevent and fix leaks.\n\n## When to Use\n\n- Reviewing code that registers event listeners or DOM handlers\n- Fixing reported memory leaks (listener counts growing over time)\n- Creating objects in methods that are called repeatedly\n- Working with model lifecycle events (onWillDispose, onDidClose)\n- Adding event subscriptions in constructors or setup methods\n\n## Audit Checklist\n\nWork through each check in order. A single missed pattern can cause thousands of leaked objects.\n\n### Step 1: DOM Event Listeners\n\n**Rule**: Never use raw `.onload`, `.onclick`, or `addEventListener()` directly. Always use `addDisposableListener()`.\n\n```typescript\n\u002F\u002F BAD — leaks a listener every call\nthis.iconElement.onload = () => { ... };\n\n\u002F\u002F GOOD — tracked and disposable\nthis._register(addDisposableListener(this.iconElement, 'load', () => { ... }));\n```\n\n**Validated by**: PR #280566 — Extension icon widget leaked 185 listeners after 37 toggles.\n\n### Step 2: One-Time Events\n\n**Rule**: Use `Event.once()` for events that should only fire once (lifecycle events, close events, first-change events).\n\n```typescript\n\u002F\u002F BAD — listener stays registered forever after first fire\nmodel.onDidDispose(() => store.dispose());\n\n\u002F\u002F GOOD — auto-removes after first invocation\nEvent.once(model.onDidDispose)(() => store.dispose());\n```\n\n**Validated by**: PRs #285657, #285661 — Terminal lifecycle hacks replaced with `Event.once()`.\n\n### Step 3: Repeated Method Calls\n\n**Rule**: Objects created in methods called multiple times must NOT be registered to the class `this._register()`. Use `MutableDisposable` or return `IDisposable` to the caller.\n\n```typescript\n\u002F\u002F BAD — every call adds another listener to the class store\nstartSearch() {\n    this._register(this.model.onResults(() => { ... }));\n}\n\n\u002F\u002F GOOD — MutableDisposable ensures max 1 listener\nprivate readonly _searchListener = this._register(new MutableDisposable());\n\nstartSearch() {\n    this._searchListener.value = this.model.onResults(() => { ... });\n}\n```\n\nWhen the event should only fire once per method call, combine `Event.once()` with `MutableDisposable` — this auto-removes the listener after the first invocation while still guarding against repeated calls:\n\n```typescript\nprivate readonly _searchListener = this._register(new MutableDisposable());\n\nstartSearch() {\n    this._searchListener.value = Event.once(this.model.onResults)(() => { ... });\n}\n```\n\n**Validated by**: PR #283466 — Terminal find widget leaked 1 listener per search.\n\n### Step 4: Model-Tied DisposableStores\n\n**Rule**: When creating a `DisposableStore` tied to a model's lifetime, register `model.onWillDispose(() => store.dispose())` to the store itself.\n\n```typescript\nconst store = new DisposableStore();\nstore.add(model.onWillDispose(() => store.dispose()));\nstore.add(model.onDidChange(() => { ... }));\n```\n\n**Validated by**: Pattern used in `chatEditingSession.ts`, `fileBasedRecommendations.ts`, `testingContentProvider.ts`.\n\n### Step 5: Resource Pool Patterns\n\n**Rule**: When using factory methods that create pooled objects (lists, trees), disposables must be registered to the individual item, not the pool class.\n\n```typescript\n\u002F\u002F BAD — registers to pool, never cleaned per item\ncreateItem() {\n    const item = new Item();\n    this._register(item.onEvent(() => { ... }));\n    return item;\n}\n\n\u002F\u002F GOOD — wrap with item-scoped disposal\ncreateItem(): IDisposable & Item {\n    const store = new DisposableStore();\n    const item = new Item();\n    store.add(item.onEvent(() => { ... }));\n    return { ...item, dispose: () => store.dispose() };\n}\n```\n\n**Validated by**: PR #290505 — Chat content parts CollapsibleListPool and TreePool leaked disposables.\n\n### Step 6: Test Validation\n\n**Rule**: Every test suite that creates disposable objects must call `ensureNoDisposablesAreLeakedInTestSuite()`.\n\n```typescript\nimport { ensureNoDisposablesAreLeakedInTestSuite } from '..\u002F..\u002F..\u002F..\u002Fbase\u002Ftest\u002Fcommon\u002Futils.js';\n\nsuite('MyFeature', () => {\n    ensureNoDisposablesAreLeakedInTestSuite();\n\n    test('does something', () => {\n        \u002F\u002F test disposables are tracked automatically\n    });\n});\n```\n\n## Quick Reference\n\n| Scenario | Pattern | Anti-Pattern |\n|----------|---------|-------------|\n| DOM events | `addDisposableListener()` | `.onclick =`, `addEventListener()` |\n| One-time events | `Event.once(event)(handler)` | `event(handler)` for lifecycle |\n| Repeated methods | `MutableDisposable` or return `IDisposable` | `this._register()` in non-constructor |\n| Model lifecycle | `store.add(model.onWillDispose(...))` | Forgetting cleanup |\n| Pooled objects | Item-scoped `DisposableStore` | Pool-scoped `this._register()` |\n| Tests | `ensureNoDisposablesAreLeakedInTestSuite()` | No leak checking |\n\n## Verification\n\nAfter fixing leaks, verify by:\n1. Checking listener counts before\u002Fafter repeated operations\n2. Running `ensureNoDisposablesAreLeakedInTestSuite()` in tests\n3. Confirming object counts stabilize (don't grow linearly with usage)\n4. **For chat-specific leaks**: Run the chat memory leak checker via `pnpm run perf:chat-leak` (see the `chat-perf` skill). It sends N messages in a single session, forces GC between each, and uses linear regression on heap\u002FDOM samples to detect per-message growth. A slope above 2 MB\u002Fmsg indicates a leak. Use `--messages 20 --verbose` for more accurate results.\n",{"name":5,"description":7},"main","d2b1bf2230b505648e972e81d854743de79b65af",".github\u002Fskills\u002Fmemory-leak-audit",43828,"https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002Fvscode","https:\u002F\u002Fcode.visualstudio.com","https:\u002F\u002Fgithub.com\u002Fmicrosoft","https:\u002F\u002Fopensource.microsoft.com","Open source projects and samples from Microsoft","2026-11-14 03:06:00",{"source":8,"skillName":5,"commands":51,"prompt":61,"zipAvailable":62},[52,55,58],{"tool":53,"command":54},"npx","npx skills add microsoft\u002Fvscode --skill memory-leak-audit",{"tool":56,"command":57},"bunx","bunx skills add microsoft\u002Fvscode --skill memory-leak-audit",{"tool":59,"command":60},"pnpm","pnpm dlx skills add microsoft\u002Fvscode --skill memory-leak-audit","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002Fvscode\u002Fblob\u002Fmain\u002F.github\u002Fskills\u002Fmemory-leak-audit\u002FSKILL.md",true,[],[65,89,110,124,139,155],{"skillNo":66,"name":67,"nameZh":6,"description":68,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":69,"categories":70,"keywords":71,"publishedAt":35},"01M70H0ANBKZAVEP1NVV4K28M3","sweeper-query","Answer natural-language questions about the VS Code Sweeper's published issue index (index-\u003Cname>.json for microsoft\u002Fvscode and the enrolled family repos) — which issues are agent-ready to implement or plan, what the sweeper proposed for an assignee or area, whether the sweeper knows a report as a duplicate, the highest-value open bugs in a lane — and, for one issue, the review's full record (evidence with file citations, fix brief, proposed comment). Use ONLY when the request explicitly names the sweeper — \"sweeper\", \"vscodesweeper\", \"sweeper-query\", a sweeper verdict, record, brief or index, an agent-ready issue — or asks what \"the sweeper\" found, proposed or knows. Do NOT use for general questions about issues, duplicates, priorities or ranking that do not mention the sweeper. Read-only; discovery only.","https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002Fvscode\u002Fblob\u002Fmain\u002F.github\u002Fskills\u002Fsweeper-query\u002FSKILL.md",[],[72,73,74,75,76,34,77,78,79,80,81,82,83,84,85,86,87,88,23,22],"sweeper query","query","sweeper","review","fix","request","which","natural-language","ranking","duplicates","ready","only","read","plan","open","Citations","brief",{"skillNo":90,"name":91,"nameZh":6,"description":92,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":93,"categories":94,"keywords":95,"publishedAt":35},"01M699DRJS4YJCV600Q72SVVWE","update-skills","Create or update repository skills and instructions when major learnings are discovered during a session. Use when the user says \"learn!\", when a significant pattern or pitfall is identified, or when reusable domain knowledge should be captured for future sessions.","https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002Fvscode\u002Fblob\u002Fmain\u002Fsrc\u002Fvs\u002Fsessions\u002Fskills\u002Fupdate-skills\u002FSKILL.md",[],[96,97,32,98,99,100,101,25,102,103,104,105,106,107,108,109,34],"update","update skills","pattern","domain","learnings","reusable","session","user","instructions","knowledge","repository","learn","create","sessions",{"skillNo":111,"name":112,"nameZh":6,"description":113,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":114,"categories":115,"keywords":116,"publishedAt":35},"01M699DPWHZ72B66P82EW31RNE","update-pr","Update the pull request for the current session. Use when the user wants to push new changes to an existing PR.","https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002Fvscode\u002Fblob\u002Fmain\u002Fsrc\u002Fvs\u002Fsessions\u002Fskills\u002Fupdate-pr\u002FSKILL.md",[],[96,117,118,34,77,119,32,25,102,103,120,121,122,123],"pr","update pr","Existing","push","pull","pull request","changes",{"skillNo":125,"name":126,"nameZh":6,"description":127,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":128,"categories":129,"keywords":130,"publishedAt":35},"01M699DJMR6CE1MH5XCJZ0GFQ0","sync","Sync the current session branch with its upstream branch, or publish the current session branch to a remote. Use when the user asks to sync a branch, pull latest changes, rebase onto upstream, push current branch, publish branch, or set upstream.","https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002Fvscode\u002Fblob\u002Fmain\u002Fsrc\u002Fvs\u002Fsessions\u002Fskills\u002Fsync\u002FSKILL.md",[],[126,131,132,120,121,133,34,123,134,135,136,137,25,102,103,138],"SET","publish","rebase","latest","with","remote","upstream","branch",{"skillNo":140,"name":141,"nameZh":6,"description":142,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":143,"categories":144,"keywords":145,"publishedAt":35},"01M699DGXHX6A2A72X57R6GGHJ","sync-upstream","Update a stale session branch by rebasing onto the latest origin. Use when the upstream has moved significantly and the session needs to catch up, resolving conflicts by preserving upstream changes and adapting session work to fit.","https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002Fvscode\u002Fblob\u002Fmain\u002Fsrc\u002Fvs\u002Fsessions\u002Fskills\u002Fsync-upstream\u002FSKILL.md",[],[137,126,146,147,34,148,149,123,134,150,151,152,153,25,102,138,154,96],"sync upstream","fit","catch","catch up","origin","conflicts","stale","up","work",{"skillNo":156,"name":157,"nameZh":6,"description":158,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":159,"categories":160,"keywords":161,"publishedAt":35},"01M699DEXYFWDGW0BAXJ5QQ377","merge","Merge changes from the topic branch to the merge base branch. Use when the user wants to merge their session's work back to the base branch.","https:\u002F\u002Fgithub.com\u002Fmicrosoft\u002Fvscode\u002Fblob\u002Fmain\u002Fsrc\u002Fvs\u002Fsessions\u002Fskills\u002Fmerge\u002FSKILL.md",[],[157,102,25,154,138,103,34,162,163,123],"back","base"]