Swift deinit is (sometimes) not called for throwing or failable initializers Sometimes we may want to define a struct or class for which initialization can fail, for example in response to invalid parameter values. For this use case, Swift provides failable initializers. In this post, Jesse Squires reminds us that when initialization fails, the deinitializer is not called, and provides a short history lesson to explain why this is the case. Posted on October 18, 2020 #initialization #memory
Swift vs. Kotlin — the differences in memory management In this post Krzysztof Turek compares Swift with Kotlin in the context of iOS and Android development, explaining how each language and platform handles memory management. Posted on June 25, 2018 #memory #kotlin #iOS #android
Memory Leaks in Swift This post from Leandro Pérez looks at memory leaks in Swift. Leandro first explains what memory leaks are, and how they occur, before describing what we can do to avoid them. Posted on May 14, 2018 #memory #leak
Memory Management and Performance of Value Types In this detailed post, Bruno Rocha examines the performance differences between Swift structs and classes. Bruno explains how both are stored in memory, and provides advice on how to avoid negative performance impacts. Posted on April 22, 2018 #memory
Heap Corruption Follow-up: Size, Alignment, and Crashing Collections Greg Heo performs a post-mortem on a bug which was found in the Swift compiler. This is a great look at how Swift works with memory allocation. Greg explains some key concepts such as stride and alignment, before providing some tips on how we can efficiently investigate hard to find bugs. Posted on April 5, 2018 #memory #heap
Size, Stride, Alignment This is a fantastic look at three important properties of Swift types which relate to memory management- size, stride, and alignment. Greg Heo describes what the properties are, and when we should take them into consideration. Posted on March 24, 2018 #memory #struct
Solving a Mysterious Heap Corruption Crash This is a great post from Agnes Vasarhelyi, in which we learn how an investigation into a mysterious heap corruption crash resulted in a bug being fixed in the Swift standard library. Posted on March 15, 2018 #memory #crash
Using unit tests to identify & avoid memory leaks in Swift John Sundell demonstrates how we can use simple unit tests to identify and avoid memory leaks. John looks at three scenarios - using delegates, observers, and closures - and describes the problem that can arise with each. Posted on November 28, 2017 #memory #testing #leak
Swift Arrays Holding Elements With Weak References Marco Santarossa looks at memory management in Swift, detailing how we can use NSPointerArray to store weak references to Swift classes. Posted on May 5, 2017 #memory