인터페이스는 현지화되어 있으며, Skill 소개와 설명 문서는 선택한 언어로 AI가 자동 번역합니다. 코드·명령어·경로·전문 용어는 원문을 유지하며 원작자 문서가 우선합니다.
Skills 둘러보기
생산성 및 협업 · SKILL.md

swift-memory-management

swift-memory-management

Prevent retain cycles via ARC, weak/unowned references, and Capture Lists in Swift. Use when managing Swift ARC, avoiding retain cycles, or configuring capture lists in closures.

Independent GitHub snapshot · Automated classification · Original documentation governs

Skill 문서

GitHub

name: swift-memory-management description: Prevent retain cycles via ARC, weak/unowned references, and Capture Lists in Swift. Use when managing Swift ARC, avoiding retain cycles, or configuring capture lists in closures. metadata: triggers: files: - '**/*.swift' keywords: - weak - unowned - capture - deinit - retain

Swift Memory Management

Priority: P0 (CRITICAL)

Implementation Guidelines

ARC Fundamentals

  • Default: Strong references. ARC handles retain/release automatically.
  • Weak: Use weak if the reference can become nil during its lifetime (delegates, optional parent refs).
  • Unowned: Use unowned if the reference is guaranteed to outlive referring object (rare; prefer weak).

Capture Lists

  • Closures: [weak self] at beginning of the closure's capture list. Pattern: { [weak self] in guard let self = self else { return } }.
  • Self in Structs: No list needed — self copied by value.
  • Multiple Captures: [weak self, weak delegate].

Retain Cycles

  • Delegates: weak var delegate always. Protocol inherits from AnyObject (e.g., protocol MyDelegate: AnyObject {})..
  • Closures as Properties: Use weak or unowned in capture list.
  • Two-way References: One side must weak.

Anti-Patterns

  • No strong var delegate: Use weak.
  • No self in escaping closures: Use [weak self].
  • No unowned unless certain: Default to weak to prevent crashes.

References

Canonical response anchors

When this skill applies, preserve the following domain terminology or equivalent concrete examples in the answer when relevant:

  • beginning of the closure's capture list

  • inherits from AnyObject

  • unowned if the reference is guaranteed

  • weak if the reference can become nil

  • Additional task-grounded exact anchors: retain cycle

저장한 Skills