From swift-modern-dev
Use when investigating memory growth, retain cycles, leaks in Instruments, Task cancellation issues, or ARC problems in Swift 6 apps.
How this skill is triggered — by the user, by Claude, or both
Slash command
/swift-modern-dev:memory-leak-diagnosisThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Find and fix leaks and retain cycles using modern concurrency patterns.
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 |
npx claudepluginhub pstuart/pstuart --plugin swift-modern-devDiagnoses and fixes memory leaks and retain cycles in Swift iOS apps using Instruments, ARC concepts, weak/unowned references, and best practices.
Debug iOS app crashes, retain cycles, hangs, and build failures using LLDB, the Memory Graph Debugger, and Instruments. Profiles CPU, memory, energy, and network performance.
Reviews Swift code for concurrency safety (async/await, actors, Sendable), error handling, memory management, force unwraps, and retain cycles. Use for .swift files and SwiftUI @Observable.