# Memory leak diagnosis

> Memory leak diagnosis is an open-source agent skill for developer tools. Guides an agent to find and fix memory leaks, retain cycles and Task issues in Swift 6. It is available on Claude Code.

- **Kind:** Skill
- **Pricing:** Open source
- **Platforms:** Claude Code
- **Website:** https://github.com/pstuart/pstuart/tree/main/plugins/swift-modern-dev/skills/memory-leak-diagnosis
- **Repository:** https://github.com/pstuart/pstuart
- **GitHub stars:** 20
- **License:** MIT
- **Skill name:** memory-leak-diagnosis
- **Collection:** https://github.com/pstuart/pstuart
- **Categories:** [developer tools](https://ai-powered.com/categories/developer-tools)
- **Listing updated:** 2026-12-04

## About

This skill walks an agent through diagnosing memory growth in Swift 6 apps, focusing on retain cycles, ARC problems and long-lived Tasks that outlive their UI. It gives a decision tree that maps symptoms such as growth during navigation or closure cycles to the right Instruments view or code change.

The guidance favors structured concurrency: cancelling stored Tasks in deinit or view lifecycle hooks, checking Task.isCancelled inside loops, using weak self in stored closures, and preferring async APIs or @Observable over Combine sinks. A short Instruments path covers running the Leaks or Allocations template, exercising the suspect flow, and confirming the result in the Memory Graph.

The skill expects a Swift codebase and Xcode with Instruments available. It includes a pre-finish checklist asking the agent to identify the root cause before changing code and to re-profile afterward. It ships as a single SKILL.md with no bundled scripts.

## When your agent uses it

> Use when investigating memory growth, retain cycles, leaks in Instruments, Task cancellation issues, or ARC problems in Swift 6 apps.

## What it can access

From a static check of the files on GitHub; nothing was run.

- [Instructions only, no scripts](https://github.com/pstuart/pstuart/tree/HEAD/plugins/swift-modern-dev/skills/memory-leak-diagnosis)
- [License: MIT](https://github.com/pstuart/pstuart/tree/HEAD/plugins/swift-modern-dev/skills/memory-leak-diagnosis)

## Features

- **Symptom-based decision tree:** Maps symptoms like navigation-driven growth or delegate cycles to the appropriate diagnostic or code fix.
- **Task lifecycle cancellation:** Shows how to store, cancel and tie background Tasks to deinit, onDisappear or the .task modifier.
- **Closure capture fixes:** Covers weak self and async alternatives for stored closures that create retain cycles.
- **Instruments profiling workflow:** Step-by-step path through the Leaks and Allocations instruments, Cycles and Roots, and Memory Graph checks.
- **Common leak patterns table:** Lists frequent leak sources such as uncancelled Tasks, NotificationCenter observers and timers with their fixes.
- **Evidence-first checklist:** Requires a confirmed root cause and a clean re-profile before a fix is considered done.

## Good for

- Find why my SwiftUI app's memory keeps growing when I navigate between screens
- Check my view model for a Task that never gets cancelled
- Fix a retain cycle caused by a closure capturing self
- Review how I replaced a Combine sink with async code for leaks
- Walk me through profiling a suspected leak with Instruments

## Install

### Claude Code

This skill ships in the `swift-modern-dev` plugin. In Claude Code, add the marketplace and install the plugin (it may include other skills too):

```sh
/plugin marketplace add pstuart/pstuart
/plugin install swift-modern-dev@pstuart
```

Or copy only this skill to `~/.claude/skills/memory-leak-diagnosis`:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/pstuart/pstuart.git "$tmp" &&
mkdir -p ~/.claude/skills &&
rm -rf ~/.claude/skills/memory-leak-diagnosis &&
cp -R "$tmp/plugins/swift-modern-dev/skills/memory-leak-diagnosis" ~/.claude/skills/memory-leak-diagnosis &&
rm -rf "$tmp"
```

For one project only, put the folder in `.claude/skills/memory-leak-diagnosis` inside it instead.

### Codex

Copy the skill folder to `~/.agents/skills/memory-leak-diagnosis` to use it in every repository:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/pstuart/pstuart.git "$tmp" &&
mkdir -p ~/.agents/skills &&
rm -rf ~/.agents/skills/memory-leak-diagnosis &&
cp -R "$tmp/plugins/swift-modern-dev/skills/memory-leak-diagnosis" ~/.agents/skills/memory-leak-diagnosis &&
rm -rf "$tmp"
```

For one repository only, put the folder in `.agents/skills/memory-leak-diagnosis` inside it instead.

### Cursor

Copy the skill folder to `~/.cursor/skills/memory-leak-diagnosis` to use it in every project:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/pstuart/pstuart.git "$tmp" &&
mkdir -p ~/.cursor/skills &&
rm -rf ~/.cursor/skills/memory-leak-diagnosis &&
cp -R "$tmp/plugins/swift-modern-dev/skills/memory-leak-diagnosis" ~/.cursor/skills/memory-leak-diagnosis &&
rm -rf "$tmp"
```

For one project only, put the folder in `.cursor/skills/memory-leak-diagnosis` inside it instead.

### Gemini CLI

Run in a terminal (add `--scope workspace` to install it for the current workspace only):

```sh
gemini skills install https://github.com/pstuart/pstuart.git --path plugins/swift-modern-dev/skills/memory-leak-diagnosis
```

Or copy the folder to `~/.gemini/skills/memory-leak-diagnosis` yourself.

### VS Code

For GitHub Copilot in VS Code, copy the skill folder to `~/.copilot/skills/memory-leak-diagnosis`:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/pstuart/pstuart.git "$tmp" &&
mkdir -p ~/.copilot/skills &&
rm -rf ~/.copilot/skills/memory-leak-diagnosis &&
cp -R "$tmp/plugins/swift-modern-dev/skills/memory-leak-diagnosis" ~/.copilot/skills/memory-leak-diagnosis &&
rm -rf "$tmp"
```

For one project only, put the folder in `.github/skills/memory-leak-diagnosis` inside it instead.

### Other agents

Get the folder:

```sh
git clone --depth 1 https://github.com/pstuart/pstuart.git
```

Then copy `pstuart/plugins/swift-modern-dev/skills/memory-leak-diagnosis` into your agent's skills folder as `memory-leak-diagnosis`. Agents that support SKILL.md read one folder per skill.

## FAQ

### What does Memory leak diagnosis need to run?

It is written for Swift 6 apps and points the agent to Xcode Instruments and the Memory Graph. It bundles no scripts, so the profiling itself is done by the developer in Xcode.

### What does Memory leak diagnosis change in my project?

The skill only gives guidance. It describes fixes such as cancelling Tasks, adding weak self, and using structured async, but it does not define any file edits or automated changes.

### When is Memory leak diagnosis triggered?

It applies when a task involves memory growth, retain cycles, leaks in Instruments, Task cancellation problems or ARC issues in Swift 6 apps.

### How do I install Memory leak diagnosis in Claude Code?

Copy the skill folder from GitHub to ~/.claude/skills/memory-leak-diagnosis to use it in all your projects, or to .claude/skills/memory-leak-diagnosis in one project. Or install the swift-modern-dev plugin, which includes it: /plugin marketplace add pstuart/pstuart, then /plugin install swift-modern-dev@pstuart.

### Does Memory leak diagnosis run scripts?

No. It is instructions only, with no scripts. This comes from a static check of the files on GitHub; nothing was run. Read the files before you install it.

### Which AI agents can use Memory leak diagnosis?

Claude Code. It reads skills in the SKILL.md format; the install steps on this page show where to put the folder.

### What are the best alternatives to Memory leak diagnosis?

The closest alternatives to Memory leak diagnosis are Axiom audit memory, Swift performance optimization, Axiom performance, Performance and Improve architecture.

## Where this comes from

- Description: from the skill's own SKILL.md.

## Alternatives

- [Axiom audit memory](https://ai-powered.com/skills/axiom-audit-memory): Axiom audit memory is an open-source agent skill for developer tools.
- [Swift performance optimization](https://ai-powered.com/skills/swift-performance-optimization): Swift performance optimization is an open-source agent skill for developer tools.
- [Axiom performance](https://ai-powered.com/skills/axiom-performance-charleswiltgen-2): Axiom performance is an open-source agent skill for developer tools.
- [Performance](https://ai-powered.com/skills/performance-daveebbelaar): Performance is an open-source agent skill for developer tools.
- [Improve architecture](https://ai-powered.com/skills/improve-architecture): Improve architecture is an open-source agent skill for developer tools.
- [Axiom analyze test failures](https://ai-powered.com/skills/axiom-analyze-test-failures): Axiom analyze test failures is an open-source agent skill for developer tools.
- [Axiom analyze swiftui performance](https://ai-powered.com/skills/axiom-analyze-swiftui-performance): Axiom analyze swiftui performance is an open-source agent skill for developer tools.
- [Axiom analyze swift performance](https://ai-powered.com/skills/axiom-analyze-swift-performance): Axiom analyze swift performance is an open-source agent skill for developer tools.

---
Source: https://ai-powered.com/skills/memory-leak-diagnosis
