跳到正文
Skillpedia
网站与界面(前端)75k · #2933

memory-leaks

它能做什么

这项技能检查浏览器端代码中那些在不再需要内存时仍然占用内存的写法。适用于单页应用在长时间使用后变慢的前端开发者。

适用场景

  • ✓当你请智能体检查网页应用是否存在内存泄漏的时候。
  • ✓当用户停留在页面越久、或在不同界面间切换越多,页面就越慢的时候。
  • ✓当你在审查组件,并想确认其监听器、计时器和请求已被正确清理的时候。

技能链接

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/memory-leaks/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/memory-leaks/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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.

repo: thedaviddias/Front-End-Checklist

热度

GitHub 星标
75k
排名
#2933
许可证
MIT
更新时间
2026/10/31

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能