/ios-swift-skills:memory-leak-diagnosis-skillfrom ios-swift-skills
Diagnoses Swift/Apple-platform memory leaks, retain cycles, deinit failures, and ARC issues using Xcode Memory Graph and Instruments. Use when objects don't deallocate or memory grows across repeated workflows.
Ships in ios-swift-skills. 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.
Read when SKILL.md points to them.
Prove the lifetime bug before changing capture lists. “Memory grew,” “deinit has not run yet,” “an object is retained,” and “an allocation is leaked” describe different evidence.
ARC, weak references, and Xcode’s core memory tools apply across currently supported Swift/Apple-platform projects. State version requirements for the specific APIs in the inspected code:
Task require Swift 5.5 and the corresponding platform concurrency runtime.| Observation | Likely category | Best first tool |
|---|---|---|
| A dismissed screen remains reachable | Unwanted retention / ownership bug | Memory Graph |
| Heap grows after repeating one workflow | Persistent allocations, cache, or leak | Allocations generations |
| Leaks instrument reports unreachable blocks | Heap leak | Leaks + allocation backtrace |
| Memory falls after pressure or cache purge | Cache / transient high-water mark | Allocations + signposts |
| Process is killed under memory pressure | Excess footprint / jetsam | Organizer report, VM Tracker, Allocations |
Crash after replacing weak with unowned | Lifetime invariant violation | Crash backtrace + ownership graph |
The Leaks instrument does not find every strongly retained object. A retain cycle can remain reachable from framework or application roots and appear only in Memory Graph or repeated Allocations generations.
deinit probes to expected owners and dependencies.Use Zombies only to diagnose messaging/use-after-free. Zombies intentionally preserve deallocated objects and invalidate leak and footprint measurements.
Read examples/example_instruments_leaks.md for a repeatable capture and verification procedure.
weak when the referenced object may deallocate first. A weak property must be optional and becomes nil automatically.unowned only when the referenced object is guaranteed to outlive every access. A violated invariant traps; “avoids optional handling” is not a valid reason.protocol DataDelegate: AnyObject {}
final class StrongDelegateManager {
var delegate: (any DataDelegate)?
}
final class ScreenOwner: DataDelegate {
let manager = StrongDelegateManager()
init() { manager.delegate = self }
}
This graph cycles: owner → manager → delegate → owner. Making delegate weak breaks it. If delegate is already weak, the delegate relationship is not the cycle; inspect stored callbacks, tasks, and external owners instead.
Both links below are strong, so the graph cycles:
final class Person { var car: Car? }
final class Car { var owner: Person? }
If the car does not own its person, make Car.owner weak. Do not then describe that weak link as incrementing a retain count.
Read examples/example_retain_cycle.swift for compiling stored-closure, delegate, bidirectional, value-container, and task-lifetime examples.
Do not add [weak self] mechanically. Decide whether work should:
For indefinite work owned by a screen or model, store a task/token, cancel it in an explicit stop, and make the task avoid a strong capture across suspension points. A weak capture followed by guard let self outside an infinite loop still promotes self for the task’s entire remaining lifetime.
For AsyncStream, define who finishes the continuation and set onTermination when producer cleanup is required. For Combine, retain cancellables only for the intended owner lifetime. For NotificationCenter block observers, retain and remove the returned token. Invalidate Timer and CADisplayLink; invalidate URL sessions whose delegate lifetime should end.
Deliver UI-facing delegate callbacks and state mutations on MainActor rather than calling UIKit/AppKit from a background queue.
Structs and enums do not have identity under ARC, but they can contain reference-typed storage or escaping closures. A class can strongly own a struct that owns a closure that strongly captures the class. Standard-library collections also use internal reference storage. Analyze the complete graph rather than declaring value types incapable of participating in cycles.
Do not depend on a particular arrow color, UI icon, or exact reference count; those presentations vary by Xcode release and compiler optimization.
Distinguish bounded caches from leaks by documenting their limit, eviction trigger, response to memory pressure, and observed steady state. An unbounded cache is still a memory defect even if every object remains intentionally reachable.
Task, task groups, actors, and continuationsAsyncStream producers and consumersWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
swift-memory, arc, retain-cycles, xcode-instruments, memory-graph, leak-diagnosis
npx claudepluginhub fal3/swift-apple-skills --plugin ios-swift-skills14 skills in this plugin
/app-intents-widgetsDesign, implement, debug, and verify stable App Intents and WidgetKit integrations, including AppIntent, AppEntity, AppEnum, entity queries, AppShortcutsProvider, dependency injection, shared extension data, widget timelines, relevance, controls, Live Activity selection, deep links, handoff, confirmation, and privacy. Use when exposing app actions to Siri or Shortcuts, building configurable or interactive widgets, sharing state with extensions, or choosing the correct system surface for an action. Do not use for ordinary in-app buttons, generic SwiftUI layout, background scheduling without a widget or intent, SiriKit-only legacy work with no migration request, or Live Activity push-server implementation as the sole task./apple-evaluationsBuild, review, and debug generative AI quality regression suites with Apple's Evaluations framework, including Evaluation, datasets, metrics, Swift Testing integration, calibrated model judges, and tool-call trajectories. Use when measuring an Apple-platform intelligence feature, comparing prompts or models, or diagnosing misleading evaluation results. Do not use for ordinary deterministic unit tests, UI automation, performance profiling alone, model training, or an unrelated vendor's evaluation framework./cross-platform-app-development-skillUse when one Swift/SwiftUI product intentionally targets two or more of iOS, iPadOS, Mac Catalyst, macOS, watchOS, tvOS, or visionOS and needs shared-domain design, adaptive UI, capability boundaries, navigation, input, scenes, storage, or conditional compilation. Do not use for a single-platform feature or for non-Apple cross-platform frameworks./ios-accessibility-skillUse when iOS or iPadOS accessibility design, implementation, review, or testing involves VoiceOver, Voice Control, Switch Control, Full Keyboard Access, Dynamic Type, contrast, motion, focus, media alternatives, or Assistive Access. Do not use for generic visual styling or platform-neutral UI work with no accessibility requirement./ios-animation-graphics-skillDesign, implement, debug, and review accessible Apple-platform animation and graphics with SwiftUI animation, Canvas, TimelineView, matched geometry, phase/keyframe animators, Core Animation, and Lottie. Use for motion design, custom drawing, transitions, particles, animated symbols, UIKit/AppKit bridging, Reduce Motion, and animation performance. Prefer native SwiftUI for app UI; use Core Animation or Lottie only when their capabilities are needed. Do not use this skill for SpriteKit/Metal game engines, video rendering, or image editing unless animation integration is the specific task./iphone-duo-designUse when designing, adapting, implementing, or auditing an iOS app for iPhone Duo, including resizing, folding, vertical bars, reserved regions, state continuity, multiple scenes, camera behavior, and accessibility. Produce evidence-based readiness findings with SDK gates and fallbacks. Do not use for generic iPhone work without Duo or adaptive-layout requirements, Android foldables, Microsoft Surface Duo, Google Duo, or claims of Apple certification.Other plugins' skills for the same job