jpskill.com
💬 コミュニケーション コミュニティ

memory-leak-detection

Detect and fix memory leaks using heap snapshots, memory profiling, and leak detection tools. Use when investigating memory growth, OOM errors, or optimizing memory usage.

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o memory-leak-detection.zip https://jpskill.com/download/21463.zip && unzip -o memory-leak-detection.zip && rm memory-leak-detection.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/21463.zip -OutFile "$d\memory-leak-detection.zip"; Expand-Archive "$d\memory-leak-detection.zip" -DestinationPath $d -Force; ri "$d\memory-leak-detection.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して memory-leak-detection.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → memory-leak-detection フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
8

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

メモリリークの検出

目次

概要

メモリリークを特定して修正し、メモリ不足によるクラッシュを防ぎ、アプリケーションのパフォーマンスを最適化します。

使用する状況

  • メモリ使用量が時間とともに増加している場合
  • メモリ不足 (OOM) エラーが発生する場合
  • パフォーマンスが低下する場合
  • コンテナが再起動する場合
  • メモリ消費量が多い場合

クイックスタート

最小限の動作例:

import v8 from "v8";
import fs from "fs";

class MemoryProfiler {
  takeSnapshot(filename: string): void {
    const snapshot = v8.writeHeapSnapshot(filename);
    console.log(`Heap snapshot saved to ${snapshot}`);
  }

  getMemoryUsage(): NodeJS.MemoryUsage {
    return process.memoryUsage();
  }

  formatMemory(bytes: number): string {
    return `${(bytes / 1024 / 1024).toFixed(2)} MB`;
  }

  printMemoryUsage(): void {
    const usage = this.getMemoryUsage();

    console.log("Memory Usage:");
    console.log(`  RSS: ${this.formatMemory(usage.rss)}`);
    console.log(`  Heap Total: ${this.formatMemory(usage.heapTotal)}`);
    console.log(`  Heap Used: ${this.formatMemory(usage.heapUsed)}`);
    console.log(`  External: ${this.formatMemory(usage.external)}`);
// ... (完全な実装についてはリファレンスガイドを参照してください)

リファレンスガイド

references/ ディレクトリにある詳細な実装:

ガイド 内容
Node.js Heap Snapshots Node.js ヒープスナップショット
Memory Leak Detection Middleware メモリリーク検出ミドルウェア
Common Memory Leak Patterns 一般的なメモリリークパターン
Python Memory Profiling Python メモリプロファイリング
WeakMap/WeakRef for Cache キャッシュのための WeakMap/WeakRef
Memory Monitoring in Production 本番環境でのメモリ監視

ベストプラクティス

✅ するべきこと

  • 完了したらイベントリスナーを削除する
  • タイマーとインターバルをクリアする
  • キャッシュには WeakMap/WeakRef を使用する
  • キャッシュサイズを制限する
  • 本番環境でメモリを監視する
  • 定期的にプロファイリングを行う
  • テスト後にクリーンアップする

❌ するべきではないこと

  • 循環参照を作成する
  • 不要な大きなオブジェクトへの参照を保持する
  • リソースのクリーンアップを忘れる
  • メモリの増加を無視する
  • オブジェクトキャッシュに WeakMap をスキップする
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

Memory Leak Detection

Table of Contents

Overview

Identify and fix memory leaks to prevent out-of-memory crashes and optimize application performance.

When to Use

  • Memory usage growing over time
  • Out of memory (OOM) errors
  • Performance degradation
  • Container restarts
  • High memory consumption

Quick Start

Minimal working example:

import v8 from "v8";
import fs from "fs";

class MemoryProfiler {
  takeSnapshot(filename: string): void {
    const snapshot = v8.writeHeapSnapshot(filename);
    console.log(`Heap snapshot saved to ${snapshot}`);
  }

  getMemoryUsage(): NodeJS.MemoryUsage {
    return process.memoryUsage();
  }

  formatMemory(bytes: number): string {
    return `${(bytes / 1024 / 1024).toFixed(2)} MB`;
  }

  printMemoryUsage(): void {
    const usage = this.getMemoryUsage();

    console.log("Memory Usage:");
    console.log(`  RSS: ${this.formatMemory(usage.rss)}`);
    console.log(`  Heap Total: ${this.formatMemory(usage.heapTotal)}`);
    console.log(`  Heap Used: ${this.formatMemory(usage.heapUsed)}`);
    console.log(`  External: ${this.formatMemory(usage.external)}`);
// ... (see reference guides for full implementation)

Reference Guides

Detailed implementations in the references/ directory:

Guide Contents
Node.js Heap Snapshots Node.js Heap Snapshots
Memory Leak Detection Middleware Memory Leak Detection Middleware
Common Memory Leak Patterns Common Memory Leak Patterns
Python Memory Profiling Python Memory Profiling
WeakMap/WeakRef for Cache WeakMap/WeakRef for Cache
Memory Monitoring in Production Memory Monitoring in Production

Best Practices

✅ DO

  • Remove event listeners when done
  • Clear timers and intervals
  • Use WeakMap/WeakRef for caches
  • Limit cache sizes
  • Monitor memory in production
  • Profile regularly
  • Clean up after tests

❌ DON'T

  • Create circular references
  • Hold references to large objects unnecessarily
  • Forget to clean up resources
  • Ignore memory growth
  • Skip WeakMap for object caches

同梱ファイル

※ ZIPに含まれるファイル一覧。`SKILL.md` 本体に加え、参考資料・サンプル・スクリプトが入っている場合があります。