I have an app that is slowing down the entire OS after using it for about 30-35 minutes. The lag is gradual and I can see it builds up over time as I repeat the same operation over and over again. It’s a music app and after streaming about 15-20 tracks, the lag is unbearable.
While scrolling items in a UIScrollView, the frame rate drops below 10. A lot of frames are skipped and the UI almost locks up. If I background the app, I see this lag in the OS in the SpringBoard and basically everywhere. Scrolling the app icons in SpringBoard becomes choppy. The slide to unlock becomes choppy, etc.
How would I go about solving this issue? What could be the probably causes. I cannot cut down the code to create a minimal reproducible example as the codebase is fairly complex. I need help with understanding what could cause the OS to almost lock up. It’s not a deadlock as the UI still responds but just takes an awful long time.
What profiling tools could help shine a light on the cause of this problem? I’m suspecting it may be because of a memory leak, but surprisingly the OS hasn’t sent the app a memory warning, so I’m not entirely sure about that either.
Any help is greatly appreciated.
The problem was with a build up of animations. Activity Monitor was most useful in debugging this issue. The CPU usage of Springboard kept rising up until it shot up to 100%. So the time was clearly not being spent in my application, but in the render server residing in Springboard.
I created two animations with a huge repeat count to let them run forever. Then I added each animation to a separate layer. To create the animation, I used a lazy check, and asked the layer for any existing animations with the given key. If the layer returned nothing, I created the animation. The problem was that the layer always returned nothing, so I kept creating these forever repeating animations.
This was the problematic code.
To fix the issue, I started removing the existing animation. I could have done this at two points, either in the
animationDidStop:finished:callback, or in mysetAnimating:method, and both worked fine. Here’s the change in thesetAnimating:method.Here’s the original BROKEN code if anyone’s interested.
There is one thing I’m still curious about though. Since there can only be one active animation for a given key, shouldn’t Core Animation have removed my existing animation when I tried to add a new one with the same key? And why did
animationForKey:returnnilat all.