How to diagnose a hang, severe hang or freeze in XCode

Oscar de la Hera Gomez
Two flowers that represent Instruments and Xcode side by side. Beneath them sits the text "Diagnose Hangs and Freezes in XCode & Instruments."

If your app stalls, freezes or is delayed when in use or when coming back from the background, analyze the CPU and Memory using the debug navigator and use instruments to identify the cause.

When an app stalls or freezes it is often difficult to identify the cause. It can drive you to remove or edit code in hope of finding the cause without having confirmed the root cause.

The leading causes of stalls, hangs or freezes are using too much CPU or memory.

Luckily, XCode has a means to analyze memory and CPU and instruments to help you identify the root cause.

A screenshot of Xcode showing the memory and CPU debug inspectors.

With the app running, using the Debug Navigator on the left side, you can see how the CPU and Memory is performing as the app is being used in the foreground or when its in the background.

A screenshot of Instruments showing how we diagnosed the situation and learned that the progress indicator animation was the culprit.

We modified our Progress Indicator tutorial to remove the code that halts the animation when going into the background, this leads to a spike in CPU usage when going to the background and a sever stall when coming back to the foreground. When analyzing this with Instruments, we learned that the root cause is the animateBorder function - which was active in the background.

Looking to learn more about things you can do with Swift and XCode ?

Search our blog to find educational content on learning how to use Swift and XCode.

Any Questions?

We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.
delasign logo

Book a Free Consultation.

An icon of an email.

Click here to email us.

Fill in the details below to book a free consultation or to let us know about something else. Whatever it is, we are here to help.

How can we help you ?

Contact Details