分析 V8 堆快照,定位内存泄漏、对象滞留与 GC 后存活原因
复制安装指令,让 AI 自动完成配置 · 推荐新手
请帮我安装 askskill 上的 "heap-snapshot-analysis" 技能: 1. 下载 https://raw.githubusercontent.com/microsoft/vscode/main/.github/skills/heap-snapshot-analysis/SKILL.md 2. 保存为 ~/.claude/skills/heap-snapshot-analysis/SKILL.md 3. 装好后重载技能,告诉我可以用了
请分析这两个 .heapsnapshot 文件,对比对象数量和内存占用变化,找出增长最明显的对象类型,并说明可能的泄漏方向。
一份前后快照差异分析,列出增长对象类型、大小变化和可疑泄漏线索。
我怀疑某类已销毁对象仍被引用。请在堆快照里追踪它们的 retainer path,找出是谁让它们无法释放。
对象保留链路说明,指出关键引用路径和导致无法回收的持有者。
请检查这个堆快照,分析为什么某些对象在 GC 之后仍然存活,并给出下一步排查建议。
对存活对象的原因分析,包括可能的引用来源、分组结果和后续排查建议。
开发者在已经拿到 .heapsnapshot 文件后,可用它分析堆内对象增长情况,定位可能的内存泄漏来源。尤其适合比较某个操作前后的快照差异。
当某些本应销毁的对象仍然存在时,可以通过 retainer path 分析找出是谁在持有它们。适合定位事件监听、缓存或闭包导致的滞留问题。
面对超大 .heapsnapshot 文件时,可借助解析与流式辅助脚本只读取需要的部分,避免整文件加载失败。适合大规模内存排查场景。
文档介绍了如何在已有 .heapsnapshot 文件的前提下分析 V8 堆快照,用于排查内存泄漏、比较前后快照差异、追踪对象保留路径,以及解释对象为何在 GC 后仍存活。文档还说明了解析辅助脚本、图构建方式,以及面对超大文件时应改用流式读取而非整文件加载。
Investigate memory leaks from V8 heap snapshots (.heapsnapshot files). This skill starts when snapshots already exist: either the user provided them, DevTools exported them, or another workflow produced them. Use the helpers here to compare snapshots, group object deltas, and trace retainer paths.
Start every investigation fresh. Do NOT read, consult, or be influenced by prior investigations found in:
/memories/ (user, session, or repo memory).github/skills/heap-snapshot-analysis/scratchpad/ (previous dated subfolders and their findings.md files)Previous findings can bias the analysis toward suspects that are no longer relevant, or cause the agent to skip steps and jump to conclusions. Let the current snapshots speak for themselves. Only reference prior work if the user explicitly asks you to.
.heapsnapshot files (before/after a workflow)If the user needs the agent to launch VS Code, drive a scenario, and capture snapshots first, use the VS Code performance workflow skill before returning here for low-level snapshot analysis.
Use the helpers in parseSnapshot.ts to load snapshots. The files are often >500MB and too large for JSON.parse as a string — the helpers use Buffer-based extraction. In scratchpad scripts, import helpers from ../helpers/*.ts.
For very large snapshots, the helper may still be too eager. Node cannot create a Buffer larger than roughly 2 GiB, so snapshots above that size can fail with ERR_FS_FILE_TOO_LARGE even before parsing. In that case, do not try to raise --max-old-space-size and retry the same full-file read. Switch to a streaming script.
import { parseSnapshot, buildGraph } from '../helpers/parseSnapshot.ts';
const data = parseSnapshot('/path/to/snapshot.heapsnapshot');
const graph = buildGraph(data);
When a snapshot is too large to load into a single Buffer, write scratchpad scripts that scan and parse only the sections needed for the question. Use streamSnapshot.mjs for the common streaming primitives instead of copying them between scratch scripts.
Useful tricks:
"nodes":, "edges":, "strings":, and "trace_function_infos":. This lets follow-up scripts jump directly to the large arrays instead of searching the whole file repeatedly.snapshot.meta separately from the small header at the start of the file. Use meta.node_fields, meta.node_types, meta.edge_fields, and meta.edge_types to avoid hard-coding tuple widths.nodes and edges, keep a small carryover string between chunks, split on commas, and process complete numeric tokens as they arrive.strings table unless the investigation truly needs it. If you only need suspicious names, collect string indexes from matching nodes/edges first, then resolve only those indexes in a second streaming pass.…
它用于分析 V8 的 .heapsnapshot 文件,帮助排查内存泄漏、对象滞留以及 GC 后仍存活的原因。它还支持快照对比、retainer path 分析和辅助脚本解析。
需要已经存在的 .heapsnapshot 文件,可能由用户提供、DevTools 导出,或由其他工作流生成。如果还需要先启动场景并抓取快照,文档建议先使用 VS Code 性能工作流技能。
不一定。文档提到文件常常超过 500MB,而超过约 2 GiB 时可能因 Buffer 限制报错,此时应改用流式脚本读取所需片段,而不是简单增加内存重试。
运行聊天性能基准与内存泄漏检查,定位聊天界面回归和性能问题。
帮助开发者定位并读取 Code OSS 开发构建日志,快速排查运行与扩展问题。
为 AI 编码助手生成或更新聊天定制配置文件,统一协作与开发体验
帮助开发者验证 Azure DevOps 流水线改动,快速排查构建与 YAML 配置问题。
将当前会话分支的修改合并回基础分支,便于整合开发成果。
帮助开发者创建和维护组件截图测试夹具,并优化组件的可测试性。
帮助你快速查询指标、分析趋势成因,并生成面向干系人的数据报告。
帮助分析内存转储并运行取证插件,快速定位安全事件线索
自动驱动 VS Code 性能与内存排查,生成可复现分析结果与对比证据。
帮助分析 Windows 崩溃转储,定位异常线程模块并支持安全修补与测试。
分析 hermesvm 在一段提交范围内的二进制体积变化与回归原因
扫描 JavaScript/TypeScript 事件监听泄漏风险并生成修复补丁