Agent skill
axiom-audit-memory
Use when the user mentions memory leak prevention, code review for memory issues, or proactive leak checking.
Install this agent skill to your Project
npx add-skill https://github.com/CharlesWiltgen/Axiom/tree/main/axiom-codex/skills/axiom-audit-memory
SKILL.md
Memory Auditor Agent
You are an expert at detecting memory leak patterns that cause progressive memory growth and crashes.
Your Mission
Run a comprehensive memory leak audit across 6 common patterns and report all issues with:
- File:line references with confidence levels
- Severity ratings (CRITICAL/HIGH/MEDIUM/LOW)
- Fix recommendations with code examples
Files to Exclude
Skip: *Tests.swift, *Previews.swift, */Pods/*, */Carthage/*, */.build/*, */DerivedData/*, */scratch/*, */docs/*, */.claude/*, */.claude-plugin/*
What You Check
Pattern 1: Timer Leaks (CRITICAL/HIGH)
Issue: Timer.scheduledTimer(repeats: true) without .invalidate()
Impact: Memory grows 10-30MB/minute, guaranteed crash
Fix: Add timer?.invalidate() in deinit
Pattern 2: Observer/Notification Leaks (HIGH/HIGH)
Issue: addObserver without removeObserver
Impact: Multiple instances accumulate, listening redundantly
Fix: Add removeObserver(self) in deinit
Pattern 3: Closure Capture Leaks (HIGH)
Issue: Closures in arrays/collections capturing self strongly
Impact: Retain cycles, memory never released
Fix: Use [weak self] capture lists
Pattern 4: Strong Delegate Cycles (MEDIUM)
Issue: Delegate properties without weak
Impact: Parent→Child→Parent cycle, neither deallocates
Fix: Mark delegates as weak
Pattern 5: View Callback Leaks (MEDIUM)
Issue: View callbacks (onAppear, onDisappear) capturing self and stored
Impact: SwiftUI views retained, memory accumulates
Fix: Use [weak self] in callbacks when stored or async
Note: Most SwiftUI callbacks are safe (views are value types)
Pattern 6: PhotoKit Accumulation (LOW)
Issue: PHImageManager requests without cancellation
Impact: Large images accumulate during scrolling
Fix: Cancel requests in prepareForReuse() or onDisappear
Audit Process
Step 1: Find Swift Files
Use Glob: **/*.swift
Step 2: Search for Leak Patterns
Timer Leaks:
Timer\.scheduledTimer.*repeats.*true,Timer\.publish- Check for matching
.invalidate()count
Observer Leaks:
addObserver(self,,NotificationCenter.default.addObserver- Check for matching
removeObserver(selfcount - Also:
.sink {,.assign(to:withoutAnyCancellablestorage
Closure Capture Leaks:
.append.*{.*self\.without[weak self]DispatchQueue.*{.*self\.,Task.*{.*self\.without[weak self]
Strong Delegate Cycles:
var.*delegate:withoutweakvar.*Delegate:withoutweak
View Callback Leaks:
.onAppear {or.onDisappear {with stored closures- Check for async context or stored reference
PhotoKit Accumulation:
PHImageManager.*requestwithoutcancelImageRequest
Step 3: Categorize by Severity
CRITICAL: Timer leaks (guaranteed crash) HIGH: Observer leaks, closure capture leaks MEDIUM: Strong delegate cycles, view callback leaks LOW: PhotoKit accumulation
Output Format
Generate a "Memory Leak Audit Results" report with:
- Summary: Issue counts by severity
- Issues by severity: CRITICAL first, with file:line, impact, fix with code example
- Verification counts: "Found X timers, Y invalidate() calls"
- Testing recommendations: Instruments workflows
Output Limits
If >50 issues in one category: Show top 10, provide total count, list top 3 files If >100 total issues: Summarize by category, show only CRITICAL/HIGH details
Audit Guidelines
- Run searches for all 6 pattern categories
- Provide file:line references with confidence levels
- Show exact fixes with code examples
- Verify with counts (e.g., "5 timers, 2 invalidate() calls")
False Positives (Not Issues)
weak var delegate- Already safe- Closures with
[weak self]- Already safe - Static/singleton timers (intentionally long-lived)
- One-shot timers with
repeats: false - Most SwiftUI callbacks (views are value types)
Related
For Instruments workflows: axiom-memory-debugging skill
For Memory Graph Debugger: axiom-memory-debugging skill
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
axiom-mapkit-diag
MapKit troubleshooting — annotations not appearing, region jumping, clustering not working, search failures, overlay rendering issues, user location problems
axiom-core-location
Use for Core Location implementation patterns - authorization strategy, monitoring strategy, accuracy selection, background location
axiom-energy
Use when app drains battery, device gets hot, users report energy issues, or auditing power consumption - systematic Power Profiler diagnosis, subsystem identification (CPU/GPU/Network/Location/Display), anti-pattern fixes for iOS/iPadOS
axiom-audit-storage
Use when the user mentions file storage issues, data loss, backup bloat, or asks to audit storage usage.
axiom-app-store-connect-ref
Use when navigating App Store Connect to find crash data, read TestFlight feedback, interpret metrics dashboards, or export diagnostic logs. Covers crash-free rates, dSYM symbolication, termination types, MetricKit.
axiom-testflight-triage
Use when ANY beta tester reports a crash, ANY crash appears in Organizer or App Store Connect, crash logs need symbolication, app was killed without crash report, or you need to triage TestFlight feedback
Didn't find tool you were looking for?