memory-leaks
它能做什么
这项技能检查浏览器端代码中那些在不再需要内存时仍然占用内存的写法。适用于单页应用在长时间使用后变慢的前端开发者。
适用场景
- ✓当你请智能体检查网页应用是否存在内存泄漏的时候。
- ✓当用户停留在页面越久、或在不同界面间切换越多,页面就越慢的时候。
- ✓当你在审查组件,并想确认其监听器、计时器和请求已被正确清理的时候。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/memory-leaks/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我的网页应用用得越久越慢。请帮我检查代码中是否有内存泄漏。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会查找从未被移除的事件监听器、一直在运行的计时器、对已移除页面元素的引用,以及在视图消失后仍在继续的请求。然后它会建议清理步骤。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Prevent common memory leak patterns
Memory leaks cause applications to consume increasing amounts of memory over time, eventually slowing the browser tab or crashing it. In single-page applications, where users don't reload the page, small leaks in components accumulate with each navigation and can make an app unusable after 30 minutes of use.
Quick Reference
- Remove event listeners when the element or component is destroyed
- Clear setInterval and setTimeout when they're no longer needed
- Avoid storing DOM references in long-lived objects after elements are removed
- Use WeakMap and WeakSet when storing metadata about objects you don't own
- Use AbortController to cancel stale async requests when UI state changes
Check
Analyze this code for memory leak patterns: uncleaned event listeners, retained DOM references after removal, closures holding large objects, and uncleared timers. Also flag fetches and async tasks that continue after the owning component or view is gone.
Fix
Fix the memory leaks in this code by cleaning up event listeners, clearing timers, canceling stale async requests, and releasing DOM references when they're no longer needed.
Explain
Explain the four most common JavaScript memory leak patterns and how to detect them with Chrome DevTools.
Code Review
Review scripts, client components, and browser execution paths related to Prevent common memory leak patterns. Flag exact imports, event handlers, runtime side effects, or blocking operations that violate the rule, and state how the change should be verified in the browser.
For full implementation details, code examples, and framework-specific guidance,
see references/rule.md.
Rule page: https://frontendchecklist.io/rules/javascript/memory-leaks
常见问题
我如何自己确认泄漏?
这项技能建议使用 Chrome DevTools 观察内存使用情况,以发现泄漏模式。
AbortController 有什么用?
它可以在用户已经离开时取消过时的请求,使结果不会更新到旧的界面上。
最常见的泄漏模式有哪些?
这项技能涵盖未清理的事件监听器、被保留的 DOM 引用、持有大对象的闭包,以及未清除的计时器。
详情
作者的原始描述
Use when reviewing scripts, client components, bundles, or runtime behavior related to Prevent common memory leak patterns. Inspect both source code and the browser execution path so fixes target the real bottleneck or bug.
热度
- GitHub 星标
- 75k
- 排名
- #2933
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。