Chuyển đến nội dung
Skillpedia
Website và giao diện (frontend)75k · #2933

memory-leaks

Skill này làm gì

Skill này xem xét code phía trình duyệt để tìm các mẫu giữ bộ nhớ dù không còn cần nữa. Skill dành cho lập trình viên front end mà ứng dụng một trang chậm dần trong các phiên dài.

Khi nào nên dùng

  • ✓Khi bạn nhờ agent kiểm tra một web app có rò rỉ bộ nhớ không.
  • ✓Khi trang càng chậm nếu người dùng mở nó lâu hoặc chuyển qua lại giữa các màn hình.
  • ✓Khi bạn rà soát một component và muốn xác nhận listener, bộ hẹn giờ và yêu cầu của nó được dọn dẹp.

Liên kết skill

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

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/memory-leaks/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Web app của tôi càng dùng lâu càng chậm. Bạn có thể kiểm tra code xem có rò rỉ bộ nhớ không?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent tìm các event listener không bao giờ bị gỡ, bộ hẹn giờ vẫn chạy, tham chiếu tới phần tử đã bị xóa và các yêu cầu tiếp tục chạy sau khi màn hình đã rời đi. Sau đó gợi ý các bước dọn dẹp.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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

Câu hỏi thường gặp

Tôi có thể tự xác nhận rò rỉ không?

Skill gợi ý dùng Chrome DevTools để theo dõi mức dùng bộ nhớ và phát hiện các mẫu rò rỉ.

AbortController dùng để làm gì?

Nó hủy các yêu cầu đã lỗi thời khi người dùng đã chuyển đi, để kết quả của chúng không cập nhật một màn hình cũ.

Những mẫu rò rỉ phổ biến nhất là gì?

Skill nêu listener sự kiện không được gỡ, tham chiếu DOM bị giữ lại, closure giữ các đối tượng lớn và bộ hẹn giờ không được xóa.

Chi tiết

Mô tả gốc của tác giả

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

Độ phổ biến

Sao GitHub
75k
Vị trí xếp hạng
#2933
Giấy phép
MIT
Cập nhật
31/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự