Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

swift-memory-management

/swift-memory-management

Zapobiega cyklom retain przez ARC, referencje weak i unowned oraz capture lists w closures Swift.

Licencja
MIT
Ostatnia zmiana repozytorium
22.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
3
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 22.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Zapobiega cyklom retain przez ARC, referencje weak i unowned oraz capture lists w closures Swift.

Oryginalny opis (EN)

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.

Jak działa

  1. Priority: P0 (CRITICAL)
  2. Implementation Guidelines
  3. Anti-Patterns
  4. References
  5. Canonical response anchors
Sekcje z nagłówków SKILL.md, w oryginale · 43 linii, 231 słów
Podgląd SKILL.md
---
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

- [Capture Lists & Retain Cycles](references/implementation.md)

## 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
Pliki w paczce (3)
  • SKILL.md 2 KB
  • evals/evals.json 2 KB
  • references/implementation.md 1 KB

Wersje

W bazie nie ma innych skilli o nazwie swift-memory-management.

Migawka bazy z 13.11.2026 · wersja paczki 992792e1acfa (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 1 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100memory-leak-diagnosis
    Pomaga badać wzrost pamięci, cykle retain, wycieki w Instruments, problemy z anulowaniem Task i ARC w aplikacjach Swift 6.
  • 85Objective-C ARC Patterns
    Omawia ARC w Objective-C: referencje strong i weak, cykle retain, kwalifikatory własności, mostkowanie z Core Foundation i wzorce bezpiecznego kodu bez ręcznego retain i release.
  • 90Memory Leak Diagnosis Skill
    Diagnozuje wycieki pamięci i zatrzymywanie obiektów w Swift i aplikacjach Apple, używając Xcode Memory Graph oraz Instruments.
  • 95lang-swift
    Pisze i przegląda nowoczesny Swift 6: opcjonale, typy wartości, protokoły, ARC i cykle silnych referencji, współbieżność oraz Swift Package Manager.
  • 100swift-performance-pro
    Diagnozuje wydajność aplikacji Swift: koszt renderowania SwiftUI, cykle silnych referencji, czas startu i pomiary w Instruments.
  • 90Swift
    Pisze, debuguje i optymalizuje Swift: współbieżność, wycieki ARC, opcjonale, generyki, stan w SwiftUI i pakiety.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.