# Memory

> Detect and fix memory leaks. Instruments memory tracking across thousands of iterations, proves the leak with growth data, identifies the uncollected reference, and verifies the fix.

- **Type:** Skill
- **Install:** `agentstack add skill-v0idos-performance-deity-memory`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [v0idOS](https://agentstack.voostack.com/s/v0idos)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [v0idOS](https://github.com/v0idOS)
- **Source:** https://github.com/v0idOS/performance-deity/tree/main/skills/memory
- **Website:** https://v0idos.github.io/performance-deity/

## Install

```sh
agentstack add skill-v0idos-performance-deity-memory
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

Execute all four phases in order.

## Phase 1 — Isolation

1. Identify the code suspected of leaking.
2. Write a wrapper that runs it in an infinite loop or for ≥1,000,000 iterations.

## Phase 2 — Instrumentation

Inject memory tracking into the wrapper:
- Node.js: `process.memoryUsage().heapUsed` before and after each iteration.
- Python: `tracemalloc.start()` / `tracemalloc.get_traced_memory()`.
- PowerShell: `[System.GC]::GetTotalMemory($false)`.

If memory continuously grows without recovering after GC, the leak is confirmed. Show the growth numerically:
```
Iteration      0:  10 MB
Iteration 100k:  14 MB
Iteration 500k:  40 MB
```

## Phase 3 — Fix

Identify the uncollected reference:
- Event listeners not removed from detached DOM nodes
- Global arrays or caches growing without a size limit
- Closures retaining large outer-scope objects

Apply the fix:
- `removeEventListener` for DOM event listeners
- `WeakMap` / `WeakRef` for object-keyed associations that should not prevent GC
- Object pooling to reuse memory instead of allocating new objects per cycle

## Phase 4 — Report

Re-run the instrumented wrapper and present:

| Metric | Before | After |
|---|---|---|
| Memory growth per 10k ops | +50MB | +0MB |
| GC pause frequency | High | Stable |

Explain the root cause and the specific reference that was being retained.

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [v0idOS](https://github.com/v0idOS)
- **Source:** [v0idOS/performance-deity](https://github.com/v0idOS/performance-deity)
- **License:** MIT
- **Homepage:** https://v0idos.github.io/performance-deity/

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-v0idos-performance-deity-memory
- Seller: https://agentstack.voostack.com/s/v0idos
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
