Quickly find retain cycles in your app with this one trick.

Paul O'Neill
3 min readDec 26, 2022

Multiple times have I been given the assignment to go through the code base and find retain cycles. Retain cycles can cause some serious problems from your app having a big memory footprint to your app crashing due to out of memory warnings. Whether you’ve been given the same assignment on your team or you just want to make sure your app doesn’t have this issue, here’s a trick to quickly spot these retain cycles. Finding them in a quick manner will surely please your bosses/managers.

In this article, I’ll first explain what a retain cycle. This will be important because once you understand that, then you’ll understand the solution to finding them much easier.

What is a retain cycle?

In order to explain what a retain cycle is in Swift, it’s important to understand what ARC is. ARC is the method by which memory for references is managed in Swift. It stands for Automatic Reference Counting. ARC tracks all of the reference types that you have in memory living in the heap. For those that want to learn more about what reference types are and how they differ from value types, I wrote another article about that.

Let’s say we have an instance of an object that we have in memory. When this instance is no longer needed, or better said, when there are no more…

--

--