December 2018
Intermediate to advanced
414 pages
10h 19m
English
Now, let's write a function that creates an instance, and does nothing else:
func createLeak() { let leak = MemoryLeak()}createLeak()
When we create the new MemoryLeak instance, a self reference is set, and the retain count will be two for the duration of the function call. When the function returns, the local leak variable is not referenced anymore, so the retain count is still one, and, if there are no references to this instance in the program, we will have a leak.
Now, let's use the memory graph tool to investigate this issue:
Using this tool, at a glance, we can see the following:
Read now
Unlock full access