From 58e7c2f58bc8f954407216d5bea8496b8a40d3db Mon Sep 17 00:00:00 2001 From: Zhongwei Li Date: Sun, 30 Nov 2025 08:21:07 +0800 Subject: [PATCH] Initial commit --- .claude-plugin/plugin.json | 15 +++++ README.md | 3 + commands/detect-leaks.md | 34 +++++++++++ plugin.lock.json | 61 +++++++++++++++++++ skills/memory-leak-detector/SKILL.md | 52 ++++++++++++++++ skills/memory-leak-detector/assets/README.md | 7 +++ .../memory-leak-detector/references/README.md | 7 +++ skills/memory-leak-detector/scripts/README.md | 7 +++ 8 files changed, 186 insertions(+) create mode 100644 .claude-plugin/plugin.json create mode 100644 README.md create mode 100644 commands/detect-leaks.md create mode 100644 plugin.lock.json create mode 100644 skills/memory-leak-detector/SKILL.md create mode 100644 skills/memory-leak-detector/assets/README.md create mode 100644 skills/memory-leak-detector/references/README.md create mode 100644 skills/memory-leak-detector/scripts/README.md diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json new file mode 100644 index 0000000..c82bb24 --- /dev/null +++ b/.claude-plugin/plugin.json @@ -0,0 +1,15 @@ +{ + "name": "memory-leak-detector", + "description": "Detect memory leaks and analyze memory usage patterns", + "version": "1.0.0", + "author": { + "name": "Claude Code Plugins", + "email": "[email protected]" + }, + "skills": [ + "./skills" + ], + "commands": [ + "./commands" + ] +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..1f64c58 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# memory-leak-detector + +Detect memory leaks and analyze memory usage patterns diff --git a/commands/detect-leaks.md b/commands/detect-leaks.md new file mode 100644 index 0000000..5ad161a --- /dev/null +++ b/commands/detect-leaks.md @@ -0,0 +1,34 @@ +--- +description: Detect potential memory leaks in code +--- + +# Memory Leak Detector + +Analyze code for potential memory leaks and improper resource management. + +## Detection Patterns + +1. **Event Listeners**: Unremoved event listeners +2. **Closures**: Variables captured in closures preventing GC +3. **Timers**: Uncancelled setTimeout/setInterval +4. **Cache Growth**: Unbounded cache or collection growth +5. **Circular References**: Objects referencing each other +6. **DOM References**: Detached DOM nodes held in memory +7. **Global Variables**: Unnecessary global state accumulation + +## Analysis Process + +1. Search for common leak patterns in codebase +2. Identify resource allocation without cleanup +3. Check for proper disposal in cleanup methods +4. Analyze object lifecycle management +5. Generate detailed report with locations and fixes + +## Output + +Provide markdown report with: +- Identified leak patterns with severity ratings +- File locations and line numbers +- Code snippets showing the issue +- Recommended fixes with examples +- Prevention strategies diff --git a/plugin.lock.json b/plugin.lock.json new file mode 100644 index 0000000..cd679d5 --- /dev/null +++ b/plugin.lock.json @@ -0,0 +1,61 @@ +{ + "$schema": "internal://schemas/plugin.lock.v1.json", + "pluginId": "gh:jeremylongshore/claude-code-plugins-plus:plugins/performance/memory-leak-detector", + "normalized": { + "repo": null, + "ref": "refs/tags/v20251128.0", + "commit": "d00e5498e92f68d9e410b9d27441fa2d71c008bc", + "treeHash": "d8281f402a471aff7a3dd73f755ee21650e0360825e9de47b548e36700e33f70", + "generatedAt": "2025-11-28T10:18:33.859097Z", + "toolVersion": "publish_plugins.py@0.2.0" + }, + "origin": { + "remote": "git@github.com:zhongweili/42plugin-data.git", + "branch": "master", + "commit": "aa1497ed0949fd50e99e70d6324a29c5b34f9390", + "repoRoot": "/Users/zhongweili/projects/openmind/42plugin-data" + }, + "manifest": { + "name": "memory-leak-detector", + "description": "Detect memory leaks and analyze memory usage patterns", + "version": "1.0.0" + }, + "content": { + "files": [ + { + "path": "README.md", + "sha256": "9ea246c9e7fb116a44b97fd83bfb0e2e286c4ed93f549a60ebef50d1ec3e5796" + }, + { + "path": ".claude-plugin/plugin.json", + "sha256": "29bcf7536f268bb6f37f98a46794a7d094f0aa59e2710a86bc57700bddf2e6b5" + }, + { + "path": "commands/detect-leaks.md", + "sha256": "a6faf441b683b81ae470ff092db2ae63366266c7d40d8965613aef763d8d18cb" + }, + { + "path": "skills/memory-leak-detector/SKILL.md", + "sha256": "19bba98b96199ca8682a33df0a0b281058cf063d38362142c0eea8d0829d56e3" + }, + { + "path": "skills/memory-leak-detector/references/README.md", + "sha256": "32c25111af368453a70125adf03e2d9f361a821af15aee2c3c2aab854e92d56c" + }, + { + "path": "skills/memory-leak-detector/scripts/README.md", + "sha256": "56d9ea70146f338f8f8a737265b3293ab00dab634c1144e1398bdde68cc72222" + }, + { + "path": "skills/memory-leak-detector/assets/README.md", + "sha256": "f566a2694628726a7259ef99895488514e6c63e87b6fe20a2d6052a88c3ae51c" + } + ], + "dirSha256": "d8281f402a471aff7a3dd73f755ee21650e0360825e9de47b548e36700e33f70" + }, + "security": { + "scannedAt": null, + "scannerVersion": null, + "flags": [] + } +} \ No newline at end of file diff --git a/skills/memory-leak-detector/SKILL.md b/skills/memory-leak-detector/SKILL.md new file mode 100644 index 0000000..aadd4c0 --- /dev/null +++ b/skills/memory-leak-detector/SKILL.md @@ -0,0 +1,52 @@ +--- +name: detecting-memory-leaks +description: | + This skill enables Claude to detect potential memory leaks and analyze memory usage patterns in code. It is triggered when the user requests "detect memory leaks", "analyze memory usage", or similar phrases related to memory leak detection and performance analysis. The skill identifies potential issues such as unremoved event listeners, closures preventing garbage collection, uncancelled timers, unbounded cache growth, circular references, detached DOM nodes, and unnecessary global state accumulation. It then provides detailed fix recommendations. Use this skill to proactively identify and resolve memory leaks, improving application performance and stability. +allowed-tools: Read, Write, Edit, Grep, Glob, Bash +version: 1.0.0 +--- + +## Overview + +This skill helps you identify and resolve memory leaks in your code. By analyzing your code for common memory leak patterns, it can help you improve the performance and stability of your application. + +## How It Works + +1. **Initiate Analysis**: The user requests memory leak detection. +2. **Code Analysis**: The plugin analyzes the codebase for potential memory leak patterns. +3. **Report Generation**: The plugin generates a report detailing potential memory leaks and recommended fixes. + +## When to Use This Skill + +This skill activates when you need to: +- Detect potential memory leaks in your application. +- Analyze memory usage patterns to identify performance bottlenecks. +- Troubleshoot performance issues related to memory leaks. + +## Examples + +### Example 1: Identifying Event Listener Leaks + +User request: "detect memory leaks in my event handling code" + +The skill will: +1. Analyze the code for unremoved event listeners. +2. Generate a report highlighting potential event listener leaks and suggesting how to properly remove them. + +### Example 2: Analyzing Cache Growth + +User request: "analyze memory usage to find excessive cache growth" + +The skill will: +1. Analyze cache implementations for unbounded growth. +2. Identify caches that are not properly managed and recommend strategies for limiting their size. + +## Best Practices + +- **Code Review**: Always review the reported potential leaks to ensure they are genuine issues. +- **Regular Analysis**: Incorporate memory leak detection into your regular development workflow. +- **Targeted Analysis**: Focus your analysis on specific areas of your code that are known to be memory-intensive. + +## Integration + +This skill can be used in conjunction with other performance analysis tools to provide a comprehensive view of application performance. \ No newline at end of file diff --git a/skills/memory-leak-detector/assets/README.md b/skills/memory-leak-detector/assets/README.md new file mode 100644 index 0000000..47aafef --- /dev/null +++ b/skills/memory-leak-detector/assets/README.md @@ -0,0 +1,7 @@ +# Assets + +Bundled resources for memory-leak-detector skill + +- [ ] report_template.md: Template for generating memory leak analysis reports. +- [ ] example_code_with_leaks/: Directory containing example code snippets with memory leaks. +- [ ] example_code_fixed/: Directory containing example code snippets with memory leaks fixed. diff --git a/skills/memory-leak-detector/references/README.md b/skills/memory-leak-detector/references/README.md new file mode 100644 index 0000000..ed6b120 --- /dev/null +++ b/skills/memory-leak-detector/references/README.md @@ -0,0 +1,7 @@ +# References + +Bundled resources for memory-leak-detector skill + +- [ ] memory_leak_patterns.md: Documentation of common memory leak patterns and how to identify them. +- [ ] memory_analysis_tools.md: Documentation on available memory analysis tools and their usage. +- [ ] code_example_fixes.md: Example fixes for common memory leak scenarios. diff --git a/skills/memory-leak-detector/scripts/README.md b/skills/memory-leak-detector/scripts/README.md new file mode 100644 index 0000000..c177e1c --- /dev/null +++ b/skills/memory-leak-detector/scripts/README.md @@ -0,0 +1,7 @@ +# Scripts + +Bundled resources for memory-leak-detector skill + +- [ ] analyze_memory.py: Script to execute memory analysis tools and parse results. +- [ ] generate_report.py: Script to generate a human-readable report from the analysis results. +- [ ] setup_environment.sh: Script to set up the necessary environment for memory leak detection (e.g., installing tools).