0Pricing
Swift Academy · Lesson

ARC basics: strong / weak / unowned

Learn ARC reference counting and when to use strong , weak , and unowned to avoid memory leaks.

ARC in one minute

Swift uses ARC (Automatic Reference Counting). Each strong reference increases a class instance's count. When it drops to zero, deinit runs and memory is freed.

Strong by default

Strong is the default. When the last strong reference goes away, deinit is called.

final class Person {
    let name: String
    init(_ name: String) { self.name = name; print("init:", name) }
    deinit { print("deinit:", name) }
}

var p: Person? = Person("Ada")
p = nil  // ARC count -> 0, triggers deinit

All lessons in this course

  1. ARC basics: strong / weak / unowned
  2. Retain cycles & breaking with weak/unowned
  3. Value types to reduce sharing
← Back to Swift Academy