> swift-memory-management

Standards for ARC, Weak/Unowned References, and Capture Lists. Use when managing Swift ARC, avoiding retain cycles, or configuring capture lists in closures. (triggers: **/*.swift, weak, unowned, capture, deinit, retain)

fetch
$curl "https://skillshub.wtf/HoangNguyen0403/agent-skills-standard/swift-memory-management?format=md"
SKILL.mdswift-memory-management

Swift Memory Management

Priority: P0

Implementation Guidelines

ARC Fundamentals

  • Default: Strong references. Swift automatically manages retain/release.
  • Weak: Use weak for delegate patterns and parent-child relationships.
  • Unowned: Use unowned only when reference guaranteed to outlive (rare).

Capture Lists

  • Closures: Always use [weak self] or [unowned self] in escaping closures.
  • Self in Structs: No capture list needed (self is copied by value).
  • Multiple Captures: [weak self, weak delegate].

Retain Cycles

  • Delegates: Always weak var delegate.
  • Closures as Properties: Use weak or unowned in capture list.
  • two-way References: One side must be weak.

Anti-Patterns

  • Strong Delegates: **No strong var delegate**: Use weak.
  • Missing Capture List: **No self in escaping closures**: Use [weak self].
  • Unowned Misuse: **Avoid unowned**: Use weak unless certain.

References

┌ stats

installs/wk0
░░░░░░░░░░
github stars341
██████████
first seenMar 17, 2026
└────────────

┌ repo

HoangNguyen0403/agent-skills-standard
by HoangNguyen0403
└────────────

┌ tags

└────────────