/swift-modern-dev:memory-leak-diagnosisfrom swift-modern-dev
Diagnoses memory leaks, retain cycles, and Task cancellation issues in Swift 6 apps using Instruments and ARC analysis.
Ships in swift-modern-dev. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Find and fix leaks and retain cycles using modern concurrency patterns.
| ALWAYS | NEVER |
|---|---|
Cancel long-lived Tasks | Infinite Task loops without cancellation |
| Prefer structured async over stored escaping closures | Strong self in stored closures without reason |
| Profile with Instruments / Memory Graph | “Optimize” without evidence of a leak |
Prefer @Observable + async over Combine sinks | Ignore purple leak markers in Memory Graph |
weak / remove stored closures / use asyncTask, cancel in deinit / .onDisappear / .task lifecycleactor@Observable
final class SafeViewModel {
private var workTask: Task<Void, Never>?
func start() {
workTask?.cancel()
workTask = Task {
while !Task.isCancelled {
await doWork()
try? await Task.sleep(for: .seconds(1))
}
}
}
func stop() {
workTask?.cancel()
workTask = nil
}
deinit { workTask?.cancel() }
}
// Prefer .task for automatic cancellation with view lifetime
.task {
await viewModel.load()
}
| Pattern | Fix |
|---|---|
Uncancelled Task | Cancel + check Task.isCancelled |
| Stored closure capturing self | weak self or async API |
| NotificationCenter observer | AsyncSequence notifications + cancel |
| Timer | invalidate / use async loop with cancel |
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
memory-leak, retain-cycle, arc, swift-concurrency, task-cancellation, instruments
npx claudepluginhub pstuart/pstuart --plugin swift-modern-dev7 skills in this plugin
/ios-accessibilityUse when implementing or auditing VoiceOver, Dynamic Type, accessibility labels, focus, contrast, or Hit-testing for SwiftUI iOS/macOS apps./swift-anti-pattern-guardUse when reviewing Swift code for outdated patterns, modernizing a project, running architecture health checks, or grepping for ObservableObject, DispatchQueue.main, NavigationView, or Core Data./swift-app-scaffoldUse when starting a new iOS or macOS app, bootstrapping Package.swift, or scaffolding a modern SwiftUI architecture with Observation, SwiftData, NavigationStack, and Swift Testing./swift-modern-architectureUse when writing Swift or SwiftUI code, designing iOS/macOS architecture, modernizing legacy patterns, or choosing ViewModels, SwiftData, navigation, or concurrency APIs./swift-performance-optimizationUse when profiling slow SwiftUI screens, optimizing lists, reducing main-thread work, improving memory/CPU, or using Instruments Time Profiler or Swift Concurrency tools./swift-test-scaffoldUse when adding Swift tests, creating test targets, scaffolding ViewModel or service tests, or choosing Swift Testing over XCTest.Other plugins' skills for the same job