How to diagnose a hang, severe hang or freeze in XCode
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.
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.
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.