agentleFS
nainishshafinainishshafi/developer-productivity-skills/.github/skills/memory-analyzer/SKILL.md

memory-analyzer

Skill1 starsChanged todayMITView on GitHub

Language-independent static and dynamic memory risk analysis. Use when the user asks to analyze code for memory issues, OOM (Out of Memory), stack overflow, memory leaks, unbounded buffer/collection growth, or high peak memory usage in any programming language.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 6 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Before scanning code, identify:

    line 21
  2. Distinctive:

    Fix: Use bounded ring buffers, LRU/TTL caches, or periodic compaction/pruning.

    line 55
  3. Distinctive:

    Fix: Use a mutable builder/buffer with preallocated capacity, or pass read-only views/references.

    line 68
  4. Distinctive:

    If tests or a runtime environment are available, verify empirically:

    line 81
  5. Distinctive:

    Steady-State Leak Check: Run the hot path or handler for $N$ iterations (e.g., 1,000 -> 10,000 -> 50,000) and verify resident memory (RSS) …

    line 82
  6. Distinctive:

    If no issues are found in a category, explicitly state what was checked and why it is bounded.

    line 97

≈ “Common” is an estimate: at least 1 in 5 of the 364,980 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

Memory Analyzer (Language-Independent)

Perform a systematic, language-independent analysis of code to detect and prevent Out-of-Memory (OOM) errors, Stack Overflow crashes, memory leaks, and unbounded heap/stack growth.


Analysis Workflow

1. Establish Scope & Constraints

Before scanning code, identify:

  • Execution model: One-shot CLI/script vs. long-running daemon/server/event-loop/tick-handler.
  • Hot paths & entry points: Loops, request/message handlers, OnTick/OnCalculate, stream processors, and recursive functions.
  • Memory boundaries: Expected max input sizes, concurrency limits, container/process RAM limits, and call-stack size limits.

2. Stack Overflow Analysis (Call Stack & Frame Size)

Inspect for anything that can exhaust the thread or process call stack:

  1. Unbounded or Input-Controlled Recursion
    • Direct or mutual/indirect recursion where depth scales with input size, tree/graph depth, or external data rather than a small constant bound.
    • Missing, unreachable, or non-converging base cases.
    • Graph/tree traversal without visited tracking (cycles cause infinite recursion).
    • Fix: Convert to an explicit heap-allocated stack/queue (iterative traversal), or enforce an explicit max_depth guard.
  2. Oversized Stack Frames
    • Large fixed-size local arrays, structs, or buffers allocated on the stack inside functions (especially recursive or deeply nested ones).
    • Dynamic stack allocations (alloca, variable-length arrays) driven by untrusted or large sizes.
    • Fix: Allocate large buffers on the heap, reuse a preallocated scratch buffer, or pass by reference/slice.
  3. Re-entrant / Cascading Call Chains
    • Event emitters, observers, signal handlers, or callbacks that synchronously trigger themselves or re-enter the same handler.
    • Fix: Defer re-entrant work to an event queue / trampoline, or guard with a re-entrancy flag.

3. OOM & Unbounded Heap Growth Analysis

Inspect for patterns that cause heap exhaustion or severe memory spikes:

  1. Unbounded Collections, Caches & Buffers
    • Lists, maps, sets, queues, logs, or memoization tables that grow on every request/tick/message without eviction, TTL, or a hard capacity cap (max_size).
    • Fix: Use bounded ring buffers, LRU/TTL caches, or periodic compaction/pruning.
  2. Full-Payload Buffering Instead of Streaming
    • Reading entire files, HTTP bodies, database query results, or IPC payloads into memory at once (read_all, fetchall, loading full history arrays).
    • Fix: Stream in fixed-size chunks, paginate queries, or process line-by-line / record-by-record.
  3. Unbounded Concurrency / Fan-Out
    • Spawning tasks, threads, goroutines, or async futures per item in an unbounded loop without a semaphore, worker pool, or backpressure.
    • Fix: Bound concurrency with a worker pool / semaphore and apply backpressure to producers.
  4. Quadratic Allocation & Copy Spikes
    • Repeated concatenation of immutable strings, arrays, or byte buffers inside loops.
    • Deep-copying large objects/arrays on every iteration or function call instead of passing views/references.
    • Fix: Use a mutable builder/buffer with preallocated capacity, or pass read-only views/references.
  5. Retained References & Hidden Leaks
    • Closures / lambdas: Capturing large outer-scope objects or buffers that outlive their need.
    • Subscriptions / registries: Event listeners, timers, or global maps where items are registered but never removed on cleanup/error paths.
    • Slicing / sub-views: Keeping a small slice/substring that pins a huge backing array/buffer in memory.
    • Circular references: Reference cycles in reference-counted runtimes without weak references.
    • Manual / native / handle leaks: Heap allocations, file/socket handles, FFI buffers, or platform handles (e.g., indicators, graphic objects, DB cursors) missing deterministic release on all exit/error paths.

4. Dynamic Verification (When Code Can Be Executed)

If tests or a runtime environment are available, verify empirically:

  1. Steady-State Leak Check: Run the hot path or handler for $N$ iterations (e.g., 1,000 -> 10,000 -> 50,000) and verify resident memory (RSS) / heap stabilizes ($O(1)$ growth) rather than rising monotonically.
  2. Peak Memory / Large Input Check: Feed worst-case or oversized inputs (deeply nested structures, large files, high concurrency) under a constrained memory/stack limit to confirm graceful bounding or streaming.

5. Output Format

Present findings ordered by severity (Critical -> High -> Medium -> Low). For each finding, report:

  • Severity & Category: e.g., [Critical] Stack Overflow or [High] Unbounded Heap Growth
  • Location: file_path:line and symbol/function name
  • Mechanism: Why memory or stack grows (include growth order, e.g., $O(N)$ per tick, $O(D)$ stack frames)
  • Trigger: Specific input, duration, or state that causes OOM or stack overflow
  • Remediation: Concrete, minimal code change to bound memory/stack usage

If no issues are found in a category, explicitly state what was checked and why it is bounded.


Quick Review Checklist

  • All recursion has a guaranteed, small bounded depth (or is iterative).
  • No large buffers/arrays are allocated on the call stack.
  • All caches, queues, and history buffers have explicit size/TTL limits.
  • Large files, streams, and query results are processed in bounded chunks.
  • Concurrency/fan-out has bounded worker/queue limits and backpressure.
  • Subscriptions, timers, closures, and native/manual handles are released on all paths (including errors).

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.