agentsclimarketplace

Swift memory management

Skill ComeOnOliver/skillshub/skills/HoangNguyen0403/agent-skills-standard/swift-memory-management

🧠 The right skill, one API call. AI agent skills registry with token-efficient skill resolution. 5,000+ skills from 500+ top repos.

Install
npx -y skills add ComeOnOliver/skillshub --skill swift-memory-management

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

What its author says it does

Copied from the file, not written here

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)

SKILL.md

1.5 KB, as published. Nobody here has run it

Swift Memory Management

Priority: P0

Implementation Guidelines

ARC Fundamentals

  • Default: Strong references. Swift automatically manages retain/release.
  • 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 the referring object (rare; prefer weak).

Capture Lists

  • Closures: Place [weak self] at the beginning of the closure's capture list. Pattern: { [weak self] in guard let self = self else { return } }.
  • 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. The delegate protocol should inherit from AnyObject (e.g., protocol MyDelegate: AnyObject {}).
  • Closures as Properties: Use weak or unowned in capture list.
  • two-way References: One side must be 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

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.