I explain the crucial concepts of memory management in software engineering: from the most fundamental questions (what memory is and why we need to manage it) to your day-to-day tools (Automatic Reference Counting, weak and unowned references, and retain cycles) to advanced topics such as Swift’s side table, object lifecycle, and autorelease pool. This guide is meant primarily for software developers using Swift and Objective-C, but many topics remain relevant across language and platform boundaries.
This video is a compilation of the four original episodes on memory management, released in 2023–2024.
Subscribe to the Swift Bird for more in-depth engineering content, and leave a comment if you have any questions or feedback!
Support the Swift Bird by…
• …joining as a member: youtube.com/channel/UC3mDnPzYxvKHaMLANaiDDYQ/join
• …becoming a patron: patreon.com/SwiftBird
• …buying me a coffee: www.buymeacoffee.com/SwiftBird
Original Episodes & More:
• • What Memory Is & Why Manage It | Essential...
• • ARC, References & Retain Cycles | Intermed...
• • Side Table, Object Lifecycle, Unowned Refs...
• • Autorelease Pool, Lazy Initialization & Mo...
• Playlist: • Fundamentals of Software Development in Sw...…
Links:
• Automatic Reference Counting documentation in the Swift book: docs.swift.org/swift-book/documentation/the-swift-…
• Automatic Reference Counting in the (very technical) Clang documentation: clang.llvm.org/docs/AutomaticReferenceCounting.htm…
• Swift’s reference-counting source file, with comments (explains the side table, +1s shenanigans, and object lifecycle): github.com/apple/swift/blob/main/stdlib/public/Swi…
• Manual memory management in Swift: developer.apple.com/documentation/swift/manual-mem…
• unowned(safe) vs. unowned(unsafe): stackoverflow.com/questions/26553924/what-is-the-d…
• Weak references before Swift 4 (and side tables): mikeash.com/pyblog/friday-qa-2015-12-11-swift-weak…
• Weak references in Swift 4 (with side tables): mikeash.com/pyblog/friday-qa-2017-09-22-swift-4-we…
• Side tables with pictures: web.archive.org/web/20240305040507/https://maximer…
• Lazy stored properties in Swift: docs.swift.org/swift-book/documentation/the-swift-…
• Autorelease pool: developer.apple.com/documentation/foundation/nsaut…
• Autorelease pool usage: developer.apple.com/library/archive/documentation/…
• Objective-C memory management policy: developer.apple.com/library/archive/documentation/…
• Objective-C naming conventions: developer.apple.com/library/archive/documentation/…
• Cocoa naming conventions: useyourloaf.com/blog/cocoa-naming-conventions-for-…
• Garbage collection explanation from @Computerphile: • Garbage Collection (Mark & Sweep) - Comput...
• Garbage collection in detail: craftinginterpreters.com/garbage-collection.html
• Garbage collection in Cocoa (outdated): developer.apple.com/library/archive/documentation/…
• Ancient Cocoa × Java documentation (just a relic of the past): developer.apple.com/library/archive/documentation/…
• Memory management in Rust (from Google’s Comprehensive Rust): google.github.io/comprehensive-rust/memory-managem…
• Rust’s ownership concept, explained (from the Rust Book): doc.rust-lang.org/book/ch04-01-what-is-ownership.h…
Chapters:
• 0:00 Intro
• 0:46 What Is Computer Memory (RAM)?
• 2:31 Why Should I Care About Memory Management?
• 4:02 Overview of Manual Memory Management
• 5:17 Mistakes in Manual Memory Management
• 7:09 Reference Counting 101
• 8:57 Automatic Reference Counting in Swift & Objective-C
• 11:12 Retain Cycles a.k.a. Reference Cycles
• 13:16 How to Fix (or Avoid) Retain Cycles
• 15:04 Difference Between Weak and Unowned References
• 16:12 ARC Summary: Pros & Cons
• 17:42 unowned(safe) vs. unowned(unsafe)
• 20:09 Side Table in Swift
• 24:26 Object Lifecycle
• 27:53 Lazy Initialization
• 30:52 Autorelease Pool
• 34:26 Alternatives to Reference Counting
• 37:14 Tip for Your Job Interviews
The Swift Bird, a Yakov Manshin production 🎞️
#Swift #memorymanagement #softwaredevelopment
コメント