Let's dive into examples of the two most common issues: leaks and crashes related to memory issues. A memory leak occurs when one or many objects become unreachable from the rest of your program but still, in one way or another, form a cycle.
In the first example, we'll look at how to effectively leak memory, using Xcode's powerful memory graph hierarchy tool to track down issues.
In the second example, we'll explore how to debug and investigate crashes related to accessing properties that may have been deallocated.
One common way to leak objects and their memory is to create strong references between different instances, and cut off any external references.
Let's consider the following code:
class MemoryLeak { var ref: MemoryLeak? init(ref: MemoryLeak) { self.ref = ref } init() { ref = self } }
As you can see, this is some code that you'd be unlikely to write on your own, as it doesn't have a purpose, aside from showcasing a memory...