agentleFS
leaf76leaf76/agent-skills/debug-memory-leak/SKILL.md

debug-memory-leak

Skill0 starsChanged 3 months agoMITView on GitHub

Debug memory leaks in the application

The file

Show its rules and text

We split this skill into the rules it gives an agent

14 rules. About 0 are common, 11 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈11

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Add memory tracking to the worker

    line 13
  2. Distinctive:

    Check for unclosed connections or uncached data

    line 25
  3. Distinctive:

    Durable Objects: Check for unclosed WebSocket connections

    line 29
  4. Distinctive:

    KV Storage: Verify proper cleanup of large values

    line 30
  5. Distinctive:

    Caches: Ensure cache size limits are enforced

    line 31
  6. Very specific:

    Add explicit cleanup in Durable Object close() methods

    line 44
  7. Distinctive:

    Use weak references where appropriate

    line 46
  8. Distinctive:

    Ensure proper error handling to prevent resource leaks

    line 47
  9. Distinctive:

    Run load tests with memory monitoring

    line 50
  10. Distinctive:

    Verify memory usage stabilizes after garbage collection

    line 51
  11. Distinctive:

    Check for memory growth under sustained load

    line 52
  12. Very specific:

    Use console.log with memory usage timestamps

    line 56
  13. Distinctive:

    Check for event listener leaks

    line 58
  14. Very specific:

    Use WeakMap or WeakSet for temporary object storage

    line 60

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Debug Memory Leak Workflow

This workflow helps identify and debug memory leaks in the Cloudflare Workers application.

Steps

  1. Enable Memory Debugging
    • Add memory tracking to the worker
    • Enable detailed logging for memory usage
    • Set up memory profiling hooks
  2. Collect Memory Metrics
    # Check current memory usage patterns
    wrangler tail --format=json | jq '.event' | grep -i memory
  3. Analyze Heap Usage
    • Review object allocation patterns
    • Check for unclosed connections or uncached data
    • Identify long-lived objects that should be garbage collected
  4. Common Memory Leak Sources
    • Durable Objects: Check for unclosed WebSocket connections
    • KV Storage: Verify proper cleanup of large values
    • Caches: Ensure cache size limits are enforced
    • Async Operations: Confirm all futures are properly awaited
  5. Debugging Commands
    # Monitor memory usage over time
    wrangler tail --format=pretty | grep "Memory usage"
    
    # Check for hanging promises
    wrangler tail --format=json | jq '.log[] | select(.message | contains("promise"))'
  6. Fix Common Issues
    • Add explicit cleanup in Durable Object close() methods
    • Implement cache eviction policies
    • Use weak references where appropriate
    • Ensure proper error handling to prevent resource leaks
  7. Validate Fixes
    • Run load tests with memory monitoring
    • Verify memory usage stabilizes after garbage collection
    • Check for memory growth under sustained load

Tips

  • Use console.log with memory usage timestamps
  • Monitor Durable Object lifecycle closely
  • Check for event listener leaks
  • Review async/await patterns for unresolved promises
  • Use WeakMap or WeakSet for temporary object storage

Related Files

  • src/lib.rs - Main worker entry point
  • src/durable_objects/ - Durable Object implementations
  • src/services/cache.rs - Cache management
  • src/middleware/ - Request/response handling

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.